Computing.Net > Forums > Programming > unexpected T_FOREACH - PHP ERROR

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

unexpected T_FOREACH - PHP ERROR

Reply to Message Icon

Original Message
Name: NooK
Date: November 5, 2007 at 07:51:22 Pacific
Subject: unexpected T_FOREACH - PHP ERROR
OS: WinXP Pro
CPU/Ram: 2GB
Model/Manufacturer: Asus Clone
Comment:

I have been trying to display data from my wholsalers database onto my website. I feel I'm getting close, but once you fix one error, its on to the next. Im not a coder just learning PHP for the first time.

My Code:

<?php
$connect = mysql_connect ("localhost", "root", "") or die(mysql_error());
mysql_select_db("scpricelist") or die(mysql_error());
?>

<?php
mysql_select_db("scpricelist");
$query = "SELECT ProductTitle FROM pricelist WHERE PartNum = '90-PN513CE-00100'";
$results = mysql_query($query)
or die(mysql_error());
while ($record = mysql_fetch_assoc($results)foreach ($record as $value)
echo "$value";
}
?>

Basically all im trying to do is, diplay product info in my catalogue. I keep getting this error.

Parse error: syntax error, unexpected T_FOREACH in C:\wamp\www\catalog.php on line 49

LINE49
echo "$value";

What am i doing wrong, this can't be that hard....


Report Offensive Message For Removal


Response Number 1
Name: NooK
Date: November 5, 2007 at 09:54:41 Pacific
Reply: (edit)

PLEASE SEE THIS POST TOO, RELATED:
http://www.computing.net/webdevel/w...


Report Offensive Follow Up For Removal

Response Number 2
Name: SN
Date: November 6, 2007 at 21:51:56 Pacific
Reply: (edit)

You're missing some punctuation and have an extraneous bracket in there:

mysql_select_db("scpricelist");
$query = "SELECT ProductTitle FROM pricelist WHERE PartNum = '90-PN513CE-00100'";
$results = mysql_query($query)
or die(mysql_error());
while ($record = mysql_fetch_assoc($results))
foreach ($record as $value)
echo "$value";


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software