views:

62

answers:

7
+1  Q: 

php parse error

hi guys,

this was working for me for the last couple of days until this morning when I must have changed something by accident. I thought I changed back everything but it's still not working.

This is the error I'm getting

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\xxxxx\reg.php on line 169

Here is the snippet of code where the problem supposedly is:

$time = "SELECT date FROM orderdetails WHERE compName = '$companyName'";

$sql5 = mysql_query($time);

if (!mysql_query($time, $conn))
{
    die('Error: ' . mysql_error());
}

while($row = mysql_fetch_array($sql5, MYSQL_ASSOC))
{
    **$time_record = $row['date'];**
}   

$orderno = "SELECT orderNo FROM orderdetails WHERE compName = '$companyName'";

$sql4 = mysql_query($orderno);

if (!mysql_query($orderno, $conn))
{
    die('Error: ' . mysql_error());
}

while($row = mysql_fetch_array($sql4, MYSQL_ASSOC))
{
    $orderno_record = $row['orderNo'];
}

The starred line is 169 but I can't see any issues with it at all. Nor can I see any issues around it.

Can a fresh pair of eyes help? Please :)

A: 
$orderno = "SELECT `orderNo` FROM `orderdetails` WHERE `compName` = '".$companyName."'";
Alexander.Plutov
Would this matter? I haven't done this for any of my other queries, and up until now it's worked okay?
TaraWalsh
Do you tried my code?
Alexander.Plutov
A: 
replace

**$time_record = $row['date'];**

with 

$time_record = $row['date'];
Yogesh
Yeah, That's the way I have it, I only had the stars in there to indicate that it is line 169.
TaraWalsh
he added stars to show you where line 169 is.
RobertPitt
think OP is trying to highlight this line as **bold** in markdown, but doesn't translate in code ;)
Ross
@Ross, pretty much ;-)
TaraWalsh
A: 

First check whether the variable $companyName is initialized with a value or not. If it's initialized, then there is no problem with the query & you need not change it, otherwise please check the query.

Now you should also try the following statement change, because I haven't seen this type of any PHP statement in my life:-

$time_record = $row['date'];

instead of

**$time_record = $row['date'];**

Hope it helps.

Knowledge Craving
read the post: The starred line is 169 but I can't see any issues with it at all. Nor can I see any issues around it.
Ross
Hi, thanks for your reply. the variable is initialised with a value, I only have the stars there to indicate that it is line 169 - I do not have it this way in my script.
TaraWalsh
Okay, my bad. I didn't understand that at first looking.
Knowledge Craving
+3  A: 

I can tell you that there is nothing wrong with that particular snippet of code. However, that's not to say it isn't something somewhere else in the file. Perhaps you could post some more of your code if possible?

Alex
when php says line 169, PHP really means about that line givving the exception of new `carriage returns` so `168`,`169`,`170`. It will not be elsewhere.
RobertPitt
I found it! Just spotted an extra apostrophe in line 147. Thanks for the help!
TaraWalsh
@RobertPitt I believe you stand corrected!
Alex
:O +1 then I suppose :)
RobertPitt
+2  A: 

There's nothing wrong in the code posted.

Double check that the Parse error refers to the file you are checking, this happens a lot of times to me.

clinisbut
+2  A: 

$discountCostCustomer = $discountCost / 100;`

remove the back tick at the end of the line

acqu13sce
Thanks for the reply, I had spotted that myself a few minutes earlier. Silly mistake.
TaraWalsh
one of the greatest reasons for eXtreme Programming, two people, one screen spot these kinds of errors all the time :)
acqu13sce
+2  A: 

Try this - i think your original code was over complicating matters. Untested mind.

it won't solve your error but will make your code clearer.

$sql = mysql_query("SELECT `date`, `orderNo` FROM `orderdetails` WHERE `compName` = '$companyName'") 
 or die('Query failed: ' . mysql_error());

/* If just one row is returned, 
 * you don't need to do while
 * try this:
 */

$row = mysql_fetch_array($sql) or die('Can\'t retrieve records: ' . mysql_error());

$time_record = $row['date'];
$orderno_record = $row['orderNo'];
Ross
Thanks Ross! I will give it a try, it will certainly tidy up the code :)
TaraWalsh