I’m having a problem with this piece of PHP. It’s meant to print out a table of products chosen from the last page – passed through POST with names in the format ‘quantityN’ where N is a number <150 & refers to a unique ID – primary key – in the table CSGames.
I know that the problem isn’t with my $connection, as I successfully load the list in the last page.
The error:
Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "FROM" LINE 1: ...efnumber,name,platform,price WHERE refnumber='20' FROM CSGam... ^ in /berw/homes1/g/gij2/public_html/cs25010/basket.php on line 102
My live project can be found here – index>catalogue>basket.
Does anyone have any idea what’s wrong with my code? Thanks in advance.
echo "
<table border='1'>
<thead>
<tr>
<td>
Title
</td>
<td>
Platform
</td>
<td>
Price
</td>
<td>
Quantity
</td>
<td>
Total price
</td>
</tr>
</thead>
";
$id=0;
$sum=0;
while($id<150){ // Loops through the POST associative array
if($_POST['quantity'.$id]>0){
$result=pg_fetch_row(pg_query($connection,"SELECT refnumber,name,platform,price WHERE refnumber='".$id."' FROM CSGames"));
$total=$result[4]*$_POST['quantity'.$id];
echo "
<tr>
<td>
".$result[1]."
</td>
<td>
".$result[2]."
</td>
<td>
£".$result[3]."
</td>
<td>
".$_POST['quantity'.$id]."
</td>
<td>
£".$total."
</td>
</tr>
";
$sum+=$total;
}
$id++;
}
should work. SELECT statements are always structured like so:
Your query was structured like: