Link to home
Start Free TrialLog in
Avatar of alexanderfoti
alexanderfotiFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL query error - Query was empty

hi there,
i am using php and MySQL and have a form which updates a record in a table called user to be either 1 or 0.

i am receiving an error message that 'query was empty'.  i have echoed the query and am getting UPDATE users SET locked = '0' WHERE id = '83'

this works when i manually enter it into phpmyadmin.

thanks for the help,
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Post you php code
Avatar of alexanderfoti

ASKER


	$id = $_POST["id"];
	$newstatus = $_POST["lock"];
	
	include ("dbconnect.php");
	
	$query = "UPDATE users SET locked = '$newstatus' WHERE id = '$id'";

	$result = mysql_query($sql) or die ("Error in query: $query. ".mysql_error());
	
	header("Location: userdetails.php?id=$id");

Open in new window

>>        $id = $_POST["id"];
>>        $newstatus = $_POST["lock"];
 
are you sure those actually have values in them?. Try:

if(!isset($_POST['id']) || empty($_POST['id']) )
{
echo "No id supplied";
exit;
}        

if(!isset($_POST['lock']) || empty($_POST['lock']) )
{
echo "No lock supplied";
exit;
}        

        include ("dbconnect.php");
        $id = mysql_real_escape_string( $_POST["id"] );
        $newstatus = mysql_real_escape_string( $_POST["lock"] );
       
        $query = "UPDATE users SET locked = '$newstatus' WHERE id = '$id'";

        $result = mysql_query($sql) or die ("Error in query: $query. ".mysql_error());
       
        header("Location: userdetails.php?id=$id");

Perhaps you meant $_GET instead of $_POST?  As a last resort, if you are mixing them, try changing $_POST to $_REQUEST
the whole error reads:

Error in query: UPDATE users SET locked = '0' WHERE id = '83'. Query was empty

when i run this query manually in phpmyadmin, it works.
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

I'm not a php or mySQL guy but I believe the first link posted by k_murli_kris kinda gives you the answer:

You set $query, your error message displays $query but your database call is using $sql
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i have been looking at this for too long ...

thanks!
Glad you found the answer but didn't you award the points a little incorrect?
alexanderfoti, a reference to a link IS also considered a correct answer. The first link posted by k_murli_krishna correctly oulines your problem. Please have the courtesy to look through the suggestions given and credit all those helping you accordingly. slightwv and I simply re-enforced the fact/problem outlined in the link suggested by k_murli_krishna. I was expecting you to ACCEPT k_murli_krishna  comment/post as the solution, and anyone else (if you felt others helped), then you would grant ASSIST points.

This wam-bam-thank you mam/man approach to grading is frowned upon. IF we spend the time solving/researching your problem, at least have the courtesy to spend the time grading adequately.