EDIT: FIXED NOW - Please close thread mods/admins . Hey, I dont have a clue why this code is making an error: <?php //Connect to the database mysql_connect("localhost", "..._...", "...") or die(mysql_error()); mysql_select_db("..._...") or die(mysql_error()); //protection function p($string){ return htmlspecialchars($string); } //get the info $id = p($_GET['id']); $data = mysql_query("SELECT * FROM ... WHERE id='{$id}'"); $data = mysql_fetch_assoc($data); ?> PHP: Error: Thanks for your help.
You need to implement some error handling. This means that your query is not returning a valid resource/result. Replace: $data = mysql_query("SELECT * FROM ... WHERE id='{$id}'"); With: if(!$data = mysql_query("SELECT * FROM ... WHERE id='{$id}'")) { die(mysql_error()); }
You need to read this http://php.net/mysql_query And follow the example. Jestep is right, you need error handling. Does your query return anything?
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'' at line 1 That's the error I get.
Can you post the exact query that is being run? Assuming that " ... " is being replaced with your table's name, the query should work.
//get the info $id = p($_GET['id']); if(!$data = mysql_query("SELECT * FROM like WHERE id='{$id}'")) { die(mysql_error()); } $data = mysql_fetch_assoc($data); yea the dots are replaced by the table called like.
Try putting backticks around like `like`. Since like is a reserved work, is it probably causing an error. if(!$data = mysql_query("SELECT * FROM `like` WHERE id='{$id}'")) { die(mysql_error()); }
I recommend employing exception handling for your database work. Logic wise, like this: TRY block - will contain all your queries, including the connection query. when you're executing queries always check for the $variable receiving the resource or boolean. when you receive a boolean (FALSE) you will throw an exception which will terminate script immediately and go to Catch block. CATCH block - will catch your errors and it's up to you what you want to do with the message, wether to display the message or just print the actual mysql error to the browser. This approach is better because if one of your queries fail there is no need to follow with the rest of them and you don't need to terminate your script completely.