[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • Last Modified:

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,
0
alexanderfoti
Asked:
alexanderfoti
  • 4
  • 3
  • 2
  • +1
1 Solution
 
hieloCommented:
Post you php code
0
 
alexanderfotiAuthor Commented:

	$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

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
hieloCommented:
>>        $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
0
 
alexanderfotiAuthor Commented:
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.
0
 
slightwv (䄆 Netminder) Commented:
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
0
 
hieloCommented:
>>You set $query, your error message displays $query but your database call is using $sql
Bingo!

>> $result = mysql_query($sql)

should be
 $result = mysql_query( $query )
0
 
alexanderfotiAuthor Commented:
i have been looking at this for too long ...

thanks!
0
 
slightwv (䄆 Netminder) Commented:
Glad you found the answer but didn't you award the points a little incorrect?
0
 
hieloCommented:
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now