Jump to content

Recommended Posts

I have a php script that opens a database connection and then retrieves some info from a table.  It has always worked without a problem, but suddenly today, I receive a parse error when I try to run the script on my localhost server. (My local server is set up with wampserver using Apache 2.2.11, PHP 5.2.9-1 and mySQL 5.1.32)

 

This is the error message, and line 31 is the while statement below:

 

Parse error: parse error in C:\wamp\www\script.php on line 31

 

$sql="SELECT * FROM $tbl_name WHERE id='$id'";

$result=mysql_query($sql);

 

$row = mysql_fetch_array($result);

 

while($row = mysql_fetch_array($result)){

etc...

 

What could have possibly happened that would cause this script to no longer work correctly?  I did not modify anything in mySQL or Apache.

I can no longer retrieve any data from the table.  I know this is a fairly vague question, but any help would be greatly appreciated.

Thanks,

csull36

 

Take out the

$row = mysql_fetch_array($result);

line before that while loop. See if that helps.

 

Oops, sorry, that was an extra line in my post.  The actual code doesn't have that.  The thing is that the code worked perfectly fine up until now...

Looks fine to me...

 

Can we see some lines before the query?

 

Sure, it looks like this:

 

<?php

 

$host="localhost";

$user="root";

$password="password";

$db_name="database";

 

mysql_connect("$host", "$user", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

$tbl_name="tblteams";

 

 

I am pretty sure it is not a problem with the actual code, since it has always worked, but then again, I didn't change any server config settings or anything, so I am completely baffled... :(

Oops, sorry, that was an extra line in my post.  The actual code doesn't have that.

 

The fact that you are not posting actual accurate copy/pasted code means we cannot really help you. Post your actual code from the start of the file through line 31. xxxxxx out any sensitive information but don't change any syntax. Don't even change any of the php tags.

sorry, here is the exact code.  The parse error occurs here on line 19, on the open bracket for the while statement

 


<?php

$host="mysql"; // Host name
$user="user"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="database"; // Database name

mysql_connect("$host", "$user", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$tbl_name="table"; // Table name

$sql="SELECT * FROM $tbl_name WHERE id='1'";
$result=mysql_query($sql);

while($row = mysql_fetch_array($result))
{
$var = $row['field1'];
}

?>

There's no syntax error there. Also, you previously said there was an error on line 31, now you're not posting 31 lines and it's migrated to line 19? Which is it?

 

I removed some comment lines so yes, the parse error is on line 19.  I know there is no problem with the syntax.  That is why this parse error is so confusing. 

Either your php installation is corrupted, your file is corrupted (contains some non-printing character that is breaking the syntax), or you are not accurately showing what is in the file (when you post information that does not match up or starts randomly changing, you loose a lot a credibility because we only see the information you provide in your post.)

 

I would recommend copy/pasting your code into a completely new file. If that does not work, attach your file to a post so that someone else can test it on their server (do you have a different server you can test on?) Do you have other php files that do work? What else have you done to troubleshoot the problem? Has anything been updated on your computer concerning your web server or php?

Either your php installation is corrupted, your file is corrupted (contains some non-printing character that is breaking the syntax), or you are not accurately showing what is in the file (when you post information that does not match up or starts randomly changing, you loose a lot a credibility because we only see the information you provide in your post.)

 

I would recommend copy/pasting your code into a completely new file. If that does not work, attach your file to a post so that someone else can test it on their server (do you have a different server you can test on?) Do you have other php files that do work? What else have you done to troubleshoot the problem? Has anything been updated on your computer concerning your web server or php?

 

I tested some other files that should also be working properly, and they also displayed parse errors, so it looks like my php or mySQL is corrupted.  I was certain all along that the code syntax was fine (since it had always worked before).  I am going to try re-installing php. Thanks for your help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.