Kev0121 Posted March 7, 2009 Share Posted March 7, 2009 heres the error Notice: Undefined index: id in C:\wamp\www\tests\update.php on line 3 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\tests\update.php on line 6 when i add mysql_error()) onto end of query code i get this error Notice: Undefined index: id in C:\wamp\www\tests\update.php on line 3 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 '' at line 1 and heres my code <?php include 'connection.php'; $query = "SELECT * FROM `test` WHERE ID = $_GET[id]"; $result = mysql_query($query); $post = mysql_fetch_array($result); ?> Kevin Quote Link to comment https://forums.phpfreaks.com/topic/148321-mysql-php-error/ Share on other sites More sharing options...
Silverado_NL Posted March 7, 2009 Share Posted March 7, 2009 try enclosing the column and value with a single quotes like this $query = "SELECT * FROM `test` WHERE 'ID' = '$_GET[id]' "; Quote Link to comment https://forums.phpfreaks.com/topic/148321-mysql-php-error/#findComment-778717 Share on other sites More sharing options...
Philip Posted March 7, 2009 Share Posted March 7, 2009 Also, using quotes around the key is good practice - otherwise it'll look for that constant first, then automatically assume 'id' instead. <?php include 'connection.php'; if(!isset($_GET['id']) || empty($_GET['id'])) { // if there was no id in the url, or it was empty kill the script die('Invaild script parameters!'); } $query = "SELECT * FROM `test` WHERE ID = '".$_GET['id']."'"; $result = mysql_query($query); $post = mysql_fetch_array($result); ?> Make sure $_GET['id'] is getting set & has a value. Quote Link to comment https://forums.phpfreaks.com/topic/148321-mysql-php-error/#findComment-778759 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.