Jump to content

MySQL + PHP Error


Kev0121

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.