How the php gets changed in the check box?

147 5

The description of the title may be very inaccurate. The thing is:
I'm learning php, preparing a small project like todolist.
There's a data table in which the id is, ( primary key ) and thing two columns.
Now output the thing loop out and add the check box before each value. I want to select the check box, click the finish button, and I'll drop this line in sql.

Now the question is, I don't know when the check box is selected, click finish, how to get the id to this thing, and then delete it with the sql statement.

while ($row = mysql_fetch_array($query))
 {
//输入复选框
 echo"<form action="index.php" method="post" name="finish">";
 echo"<input name="a[]" type="checkbox" id="a[]" value=".$row[id]."/>";
 echo $i ;
 $i = $i + 1;
 echo $row[thing];
 echo"->" ;
 outputTheTime($row[time]);
 echo"<br/><hr/>";
 }
 echo"<input name = "finish" type = "submit" id ="finish" value = "完成"/>";
 echo"</form>";
//完成,删除事项。
 if($_POST['finish'])
 {
 for($i=0;$i<count($_POST["a"]);$i++)
 {
 $sql ="DELETE FROM todaylist WHERE id = {$_POST["a"][$i]}";//这里肯定不对吧...
 mysql_query($sql);
 }
 echo"<meta http-equiv=refresh content=0;url=index.php>";

Because it's. And just start, please ignore my, code. -

2 Answers

94 2

It's a bit of a syntax error. There's nothing wrong with it.
Once the column is underlined, the value of the key in the array must be quoted in quotation marks. ! quotation marks, this is a string. which book did you've,, don't have to be lazy. Like $row[thing], you must write $row['thing'].

This one.

echo"<input name="a[]" type="checkbox" id="a[]" value=".$row[id]."/>";

To change to

echo"<input name="a[]" type="checkbox" id="a[]" value="{$row['id']}"/>";

When deleting

$sql ="DELETE FROM todaylist WHERE id = {$_POST["a"][$i]}";

To change to, to figure out strings in double quotes.

$sql ="DELETE FROM todaylist WHERE id = {$_POST['a'][$i]}";
74 2

It's a bit of a syntax error. There's nothing wrong with it.
Once the column is underlined, the value of the key in the array must be quoted in quotation marks. ! quotation marks, this is a string. which book did you've,, don't have to be lazy. Like $row[thing], you must write $row['thing'].

This one.

echo"<input name="a[]" type="checkbox" id="a[]" value=".$row[id]."/>";

To change to

echo"<input name="a[]" type="checkbox" id="a[]" value="{$row['id']}"/>";

When deleting

$sql ="DELETE FROM todaylist WHERE id = {$_POST["a"][$i]}";

To change to, to figure out strings in double quotes.

$sql ="DELETE FROM todaylist WHERE id = {$_POST['a'][$i]}";
...