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 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]' "; 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. Link to comment https://forums.phpfreaks.com/topic/148321-mysql-php-error/#findComment-778759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.