Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 19th, 2006, 8:41 AM   #1
k4pil
Programmer
 
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4 k4pil is on a distinguished road
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
k4pil is offline   Reply With Quote
Old Feb 19th, 2006, 9:21 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Feb 19th, 2006, 9:33 AM   #3
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
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]}'";
Polyphemus_ is offline   Reply With Quote
Old Feb 19th, 2006, 2:05 PM   #4
k4pil
Programmer
 
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4 k4pil is on a distinguished road
It was that.

Thanks - solved now
k4pil is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC