Problem with parsing varible

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Problem with parsing varible

Post by nutstretch »

I am problems with obtaining a variable form the previous page.
I am being told "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"

Here is the code which triggers the action

print "<td><a href = 'search.php?id=$style'><img src='$test' width='128' height='85' alt='Click here to see more info on this shoe'></a></td>";


The code on the second page is

$style = $_GET["$style"];
$sql = "SELECT * FROM tblShoestest where StyleID like $style";

$resultID = mysql_query($sql, $linkID)or die(mysql_error());

Am i asking for the wrong thing? should i be asking for id?

What I want to happen is then the picture is clicked on, the next page goes and does a query to find out more and display

Any help appreciated
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$style = $_GET['style'];

or just do
$sql = "SELECT * FROM tblShoestest where StyleID like {$_GET['style']}"; then you don't have to create the temporary $style var.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

and don't forget to put quotes around strings in SQL:

Code: Select all

$sql = "SELECT * FROM tblShoestest WHERE StyleID='{$_GET['style']}'";
Mac
Post Reply