![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4
![]() |
Parse Error when accessing database
hi there!
I have the following code. It creates a table using an array passed from a different page. <tr>
<td><font face="Arial, Helvetica, sans-serif" size="2"><? echo "$id"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif" size="2"><? echo $name; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif" size="2"><? echo $surname; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif" size="2"><? foreach($_POST['CB'] as $k => $v)
{
echo $_POST['CB'][$k].'<br>';
}; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif" size="2"><?
//get cost of product where productID = $_POST['CB'][$k].
include '../connect.php';
foreach($_POST['CB'] as $k => $v)
{
//output a list of all products
$queryCost = "SELECT * FROM product WHERE productID = '$_POST['CB'][$k].'";
$result = mysql_query ($queryCost) or die (mysql_error()."product query");
$num = mysql_numrows($result);
mysql_close();
$prodCost=mysql_result($result,$i,"cost");
echo "$prodCost";
}//foreach
?></font></td>
<td><font face="Arial, Helvetica, sans-serif" size="2"><? echo "quantity"; ?></font></td>
</tr>$_POST['CB'] as $k => $v is working finr, i have tested it. However, when i try to query the database i get an error; Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/kapi7150/public_html/CRM/custAddProduct.php on line 83 Any help?? Thanks in advance |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I haven't looked at the code, yet (I will), but this is a PHP error, not a MySQL error. Off the top of my head, I'd be looking for a missing parenthesis, brace, or punctuation character. I'd probably be looking hardest at the query string.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
I'm not sure this has to do with the message you get (I don't know the exact meaning of all the PHP errors), but this line:
$queryCost = "SELECT * FROM product WHERE productID = '$_POST['CB'][$k].'"; should be: $queryCost = "SELECT * FROM product WHERE productID = '{$_POST['CB'][$k]}'"; |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4
![]() |
It was that.
Thanks - solved now |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|