This is frustrating because there are several things at work here...
-- firstly --
Page data (POST or GET) is ALWAYS 'character' type when received into your script -- whether or not that's how you use it in your application/database
So most times you need to "settype($id, "integer") in order to use the values in the particular case of database queries where the data=type is some numeric type
-- secondly --
MySQL query syntax generally _requires_ character data to be 'single quoted', whereas integers should be unquoted
So if your Newsid field in the MySQLK table structure is character type then use the single quotes if integer the _unquotes in the $query
((Your error messages imply that this is
likely one of the probs with the code.))
-- lastly --
For some reason (beyond my grasp) the variable substitution in PHP behaves differently for _simple_ vars ($var) as opposed to _complex_ vars like $_POST["somevarname"] and $arrayname["$othervar"]
So the conmbined solution to at least give a try
===================================================================
settype($id, "integer"); // assuming that the MySQL field-type is an integer
$id = $_GET['id']; // change to what I called a _simple_ var ;-)
// then place $id in the query as unquoted
$query = "SELECT Newsheadline, News, Contact FROM news WHERE Newsid = $id";
Hope that helps,
Tom Henry
Frank Keessen wrote:
Thanks, but not working: The error message: Error in query: SELECT Newsheadline, News, Contact FROM news WHERE Newsid = . You have an error in your SQL syntax near '' at line 1Here are both lines: $query = "SELECT Newsheadline, News, Contact FROM news WHERE Newsid = {$_GET['id']}"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); Regards, Frank ----- Original Message ----- From: "Danny Shepherd" <[EMAIL PROTECTED]> To: "Frank Keessen" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, January 15, 2003 11:54 AM Subject: Re: [PHP] Question about $_GETTry $query = "SELECT Newsheadline, News, Contact FROM news WHERE Newsid = {$_GET['id']}"; HTH Danny. ----- Original Message ----- From: "Frank Keessen" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, January 15, 2003 10:50 AM Subject: [PHP] Question about $_GET Hi All, Can you please help me with the following problem? I've had code wich was running fine with php till i've upgraded to PHP version 4.2.3. The original code line was: $query = "SELECT Newsheadline, News, Contact FROM news WHERE Newsid = '$id'"; but it's not working when you have register_globals=Off So i've read everywhere to use the $_Get: So the code looks like this: $query = "SELECT Newsheadline, News, Contact FROM news WHERE Newsid = $_GET['id']"; But all i'm getting in my browser is: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' Can someone please help? Thanks and regards, Frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php