Jump to content

PHP SQL SELECT Problem


skaero
 Share

Recommended Posts

Well I posted here because I think its a SQL problem not a PHP one. When I run this it says:

Error: 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 'WHERE id = '1' AND place = '1'' at line 1
I can't find AND being able to be used in a SELECT but thats what I need it to do.Note: the values that were in the posts were not 1
$check_result = mysql_query("SELECT * FROM table WHERE id='$_POST[id]' AND place='$_POST[place]'");$check_rows = mysql_num_rows($check_result);if ($check_rows >= "1") {echo = 'No';} else {echo = 'Yes';}

Thanks!(Sorry for bad English I been working on this for hours!)

Link to comment
Share on other sites

table is a reserved keyword in MySQL, try

$check_result = mysql_query("SELECT * FROM `table` WHERE id='{$_POST['id']}' AND place='{$_POST['place']}'");

Link to comment
Share on other sites

First of all, why are you giving a table the name 'table'? Give it a better name such as users, reviews, products, customers, etc.Second of all, the query should execute successfully when you put backticks around the table name (in this case, `table`).mysql_query("SELECT * FROM `table` WHERE id='$_POST[id]' AND place='$_POST[place]'");

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...