0

Trying to call function Sel_item and pass it the fieldname1 variable as well as the id. The passing of the id works fine, but as soon as I try to pass the fieldname1, it dies. Basically trying to pass the id and the name of the person in mysql database to another function.

$id = $row["id"];
$fieldname1 = $row["person_name"];
$fieldname2 = $row["check_in_butt"];
$fieldname3 = $row["date_time"];
$str = "";
if($fieldname2 == true) $str = "checked";
 
echo '<tr> 
  <td>'.$fieldname1.'</td>
  <td><input type="checkbox"'.$str. 'onclick="Sel_item('.$id.,.$fieldname1.')" </td>
4
  • Sel_item is a php or javascript function ?? Commented Aug 16, 2020 at 23:48
  • The comma between $id.,.$fieldname1 should be in quotes. Should be: <td><input type="checkbox" '. $str . ' onclick="Sel_item('. $id .','. $fieldname1 .')"></td>'; Commented Aug 17, 2020 at 0:58
  • @GNassro it is a javascript function being called within a php statement. pastebin.com/7P7Tzr6G This is the whole thing for context. Commented Aug 17, 2020 at 20:39
  • the answer of Abdullah look good, you must check the console of the browser , maybe you have some error in your JavaScript function Commented Aug 17, 2020 at 23:41

1 Answer 1

1

I usually make it like this. Work for me

<?php
$id = $row["id"];
$fieldname1 = $row["person_name"];
$fieldname2 = $row["check_in_butt"];
$fieldname3 = $row["date_time"];
$str = "";
if($fieldname2 == true) $str = "checked";
?>

<tr> 
    <td><?= $fieldname1 ?></td>
    <td><input type="checkbox" <?= $str ?> onclick="Sel_item('<?= $id ?>', '<?= $fieldname1 ?>')"></td>
</tr>
Sign up to request clarification or add additional context in comments.

3 Comments

Still isn't working...I made a pastebin with the whole project pastebin.com/7P7Tzr6G. This is my first time trying to code javascript / php...I built the whole thing in HTML but I realized later the need to save things to a database required more than HTML. :-\
may I know which database you are using, so that I can check it as a whole
I am using mysql database

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.