in my page i allow the administrator to list all user records with radio buttons...and he can delete record one by one using the radio button in front of the record and clicking delete button..the radio button has the value of primary key of record to be deleted..i post that value to another form and perform query operation to delete the specified record..but itz not working..
it shows error message:incorrect sql syntax..i think the problem is with radio button's value..kindly help me out of this..

include("dbconnect.php"); //for connecting database
include("printing.php"); //for printing query results
echo"<form action=\"confirm_deletus.php\" method=\"post\">"; //posted to another form
echo"<input type=\"submit\" value=\"deleteuser\" name=\"del\">";
$query="select * from users";
$re=mysql_query($query) or die
printresults($re); //list the users


$uid=$_POST["user_id"]; //user_id is the primary key got from the value of radio button
$query="delete from users where user_id=$uid";
$re=mysql_query($query) or


function printresults($res)
echo"no records found";
echo "<table bgcolor=#fffffff border=1 width=80%>";
while($p=mysql_fetch_array($res, MYSQL_NUM))
echo"<td valign=top align=left> $value </td>";
echo"</tr>"; //the radio button 's value is set to the primary key
echo"<input type=radio //of record
name=\”user_id\” value=\””.$p[“user_id”].”\”";

After a quick glance, I see that the value you're passing for $re is "mysql_query($query) or die

If memory serves me, that would not be a correct variable for mysql_num_rows.

You could always put the db select with the die statement in the dbconnect.php. That way, the value for $re would be "mysql_query($query);" which would be correct for mysql_num_rows.

If memory serves me, that would not be a correct variable for mysql_num_rows.

Nope. $result=mysql_query($query) or die(mysql_error()); will assign the resultset to $result if the query executes without any error. If it encounters any error, the script print the die statement and exit.
When you call the function, instead of echoing everything inside the function, assign it to a variable and return that variable. for example,

function print($res){
return $output;

Then you can print it in the form. Also, test if the function is serving its purpose. Have a print statement to check the flow of the function.

no ya...iam getting the racords printed correctly...but the problem is in deleting them...if i select a record by clisking the radio button near it..the radio button's value property should have the value of primary key of that particular that i may pass the value of radio button to another form and use it for my query to delete that particular record...error occurs in the line $query=delete from users where user_id=$uid;...uid is the radio button's value that i get through post..

This article has been dead for over six months. Start a new discussion instead.