php is adding ="" to the end of a string when I try to echo a button in the onclick property.
This gets sql data on an XAMPP server. It loops through and builds essentially a calendar showing all my bills and if I have paid them each month. I am using AJAX to update the database and change the paid value on a button click for each month.
I've tried various methods of using single and double quotes and escaping the quotes inside the string, but I still can't get it to output correctly.
echo $billName
foreach ($months as $v) {
//$clickstring = 'onclick="setCalendar("'.$billName.'","'.$v.'")';
$clickstring = "onclick=\"setCalendar(\"".$billName."\",\"".$v."\")";
if ($row["$v"] == "1") {
echo '<button class="paidBtn green-text"'.$clickstring . '><i class="fa fa-check" aria-hidden="true"></i></button>';
} else {
echo '<button class="unpaidBtn red-text"'.$clickstring.'><i class="fa fa-times" aria-hidden="true"></i></button>';
}
Say for instance on the first iteration $billname = "Amazon"; and $v = "jan". On the first echo Amazon is correct. However when it uses the same variable in the double click it inserts a space before it, and seems to perform a strtolower(). jan is inserted correctly, but it puts extra characters and quotation marks afterward. Here is the html output from the browser:
<button class="unpaidBtn red-text" onclick="setCalendar(" amazon","jan")=""><i class="fa fa-times" aria-hidden="true"></i></button>