Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.