hello i have this code in php
> <form name ="deleteForm"
> action="CRUD/deleteAct.php"
> method="POST"><input type="text"
> value="'.$row['id'].'"/><input
> type="submit" value="DELETE" /></form>
and when it post to deleteAct.php we have this code to get the id value
connection..
mysql_select_db('bena');
echo "delete info";
$id = $_GET['id'];
echo "$id";
$delete = "DELETE FROM activites WHERE id = $id";
$delquy = mysql_query($delet开发者_运维知识库e,$connection);
if( $delquy )
echo " information was deleted!";
i was exchanged $_POST with $_GET in the deletAct.php file but didn't solve!
<input type="text" value="'.$row['id'].'"/>
You haven't given this a name.
Try this:
<input type="text" value="'.$row['id'].'" name="id" />
and make sure you're picking up $id = $_POST['id'];
at the other page.
Also, as said in the comments, read up on SQL injection. And look at PDO too:
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
Your input filed dosen't have a name
it should be
<input type="text" name="id" value="'.$row['id'].'"/>
Also, to prevent injections
$delete = "DELETE FROM activites WHERE id = ".mysql_real_escape_string($id)."";
or use Prepared Statements
Your initial form uses the POST method, hence if you need the value of id, look in the $_POST array. Generally, it might be nice to sanitise the value anyway. It needs a name attribute though:
<input type="text" name="id" value="'.$row['id'].'"/>
//..
mysql_select_db('bena');
echo "delete info";
$id = intval($_POST['id']);
echo "$id";
$delete = "DELETE FROM activites WHERE id = $id";
$delquy = mysql_query($delete,$connection);
if( $delquy )
echo " information was deleted!";
精彩评论