alexanderfoti
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,
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,
Post you php code
See:
https://www.experts-exchange.com/questions/22475835/PHP-MYSQL-Query-is-empty-error.html
http://www.htmlforums.com/php-programming/t-retrieve-mysql-data-using-form-error-query-was-empty-105346.html
http://www.webmaster-talk.com/php-forum/65276-mysql-error-query-was-empty.html
http://stackoverflow.com/questions/636032/why-do-i-get-the-mysql-error-query-was-empty
http://codingforums.com/showthread.php?t=58259
https://www.experts-exchange.com/questions/22475835/PHP-MYSQL-Query-is-empty-error.html
http://www.htmlforums.com/php-programming/t-retrieve-mysql-data-using-form-error-query-was-empty-105346.html
http://www.webmaster-talk.com/php-forum/65276-mysql-error-query-was-empty.html
http://stackoverflow.com/questions/636032/why-do-i-get-the-mysql-error-query-was-empty
http://codingforums.com/showthread.php?t=58259
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");
>> $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
>> $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
ASKER
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.
Error in query: UPDATE users SET locked = '0' WHERE id = '83'. Query was empty
when i run this query manually in phpmyadmin, it works.
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
You set $query, your error message displays $query but your database call is using $sql
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i have been looking at this for too long ...
thanks!
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.
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.