Jump to content
Sign in to follow this  
samerhannoun

SQL Query not working

Recommended Posts

HI guys... why this code not working "SELECT * timesheet WHERE YEAR(date) = YEAR(CURDATE()) AND MONTH(date) = MONTH(CURDATE()) ";this SQL statment working fine on the database engine direct, but not working when run it via PHP page???Please any help Thank you in advance.

Share this post


Link to post
Share on other sites

Looks like you forgot 'FROM' between the * and timesheet...SELECT * FROM...

HI guys... why this code not working "SELECT * timesheet WHERE YEAR(date) = YEAR(CURDATE()) AND MONTH(date) = MONTH(CURDATE()) ";this SQL statment working fine on the database engine direct, but not working when run it via PHP page???Please any help Thank you in advance.

Share this post


Link to post
Share on other sites

i have a problem with sqli'm using this code:

                //sql guery         $squl="INSERT INTO 'messages' ('id','name' ,'email' ,'subject' ,'content','userid' )VALUES ( null,'$name',  '$mail',  '$subject',  '$content','');";           //myql query         $quuery=mysql_query($squl) or die("message query problem: ".  mysql_error()); 

the result is : "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''messages' ('id','name' ,'email' ,'subject' ,'content','userid' )VALUES ( null,'' at line 1" what is the problem?! please help me!

Edited by hatef

Share this post


Link to post
Share on other sites

You're using backquotes around the values instead of single quotes. Backquotes are only used for quoting identifiers like column and table names.

  • Like 1

Share this post


Link to post
Share on other sites

changed it to what? Show us your updated code. you're also not doing any error checking.

Edited by thescientist
  • Like 1

Share this post


Link to post
Share on other sites

i changed it to this : "

		 //sql guery	  //sql guery	 $squl="INSERT INTO 'messages' ('id','name' ,'email' ,'subject' ,'content','userid' )VALUES ( null,'".$name."',  '".$mail."',  '".$subject."',  '".$content."','');";	  //myql query	 $quuery=mysql_query($squl) or die("message query problem: ".  mysql_error());

Share this post


Link to post
Share on other sites
$squl = "INSERT INTO messages (name, email, subject, content) VALUES ('$name', '$mail', '$subject', '$content')";
Edited by Haris S

Share this post


Link to post
Share on other sites

Just to add: If one of your values is going to be a number(s), you don't have to have any quotes around that value. For example:

$sql = "INSERT INTO messages (name, email, subject, content, phone) VALUES ('$name', '$mail', '$subject', '$content', $phone)";

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...