I am trying to customize a script for checkbox.
I have progressed to the following and successfully echoed to screen:
$q="Select id, subject From subjects";
$r=mysqli_query ($d, $q);
If (mysqli_num_rows($r)>0) {
while ($row =mysqli_ferch_array($r, MYSQLI_NUM)) {
Echo "<input type=\"checkbox\" name=\"$row[1]\" value=\"$row[0]\">$row[1]";
}}
Now,
I am trying to insert the resultant data into a different table (for example student) as follows:
$q = 'INSERT INTO student (id) VALUES (?)';
$stmt = mysqli_prepare($d,$q);
mysqli_stmt_bind+param($stmt, 'i', $_POST[?);
mysqli_stmt_execute($stmt);
However, this is not working.
Where I am lost is trying to understand the variables:
$row
, $row[0]
$row[1]
and sql
'subject'
sql
'id'
What value will $_POST
receive and how do I insert into a database using the above procedural type code that was used for a select statement.
If possible, would you provide an example?
Also, any explanation of the variables listed above and their uses would be helpful!
I have looked through the site, but still am a little confused.