/    Sign up×
Community /Pin to ProfileBookmark

Getting parse error can’t figure out what I’m doing wrong. Need your expertise.

Hello everyone.

I am developing a site. I am no stranger to HTML code, as I have been writing it for years. But, this is my first foray into PHP and everytime I upload my site to my web server and run the pages, pretty much every page is coming up with a parse error. This page especially is coming up with a ‘Parse error: syntax error, unexpected T_VARIABLE, expecting ‘(‘ in /home/crescen9/public_html/logintop.php on line 9’. Here is the code for that page. I have been racking my brain trying to figure it out, it’s probably something stupid, but:

<?
session_start();
if (!isset($_SESSION[’email’])) {
mysql_connect(“localhost” , “*****“, “******”)
or die(‘Database is not responding.’);
mysql_select_db(“crescen9_Bandusers”) or die(‘Unable to connect to database’);
$query= “SELECT first_name, band_name, cdsalecount FROM Userinfo”;
$result= ‘mysql_query($query)’;
while $row= ‘mysql_fetch_assoc($result)’;
{
echo “Name :$row[‘first_name’]}<br>” .
“Band Name : $row[‘band_name’] <br>” .
“CDs Sold To Date : $row[‘cdsalecount’] <br><br>”;
}
} else {
print'<html><body bgcolor=”#888888″><center><font size=”2″ face=”verdana”>You are not logged in! Click <a href=”login.php”>here to log in!<br>
Don’t have an account? <a href=”bandusersignup.php”>Sign Up Now!!!</a></font></center></body></html>’;
}
?>

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Oct 29.2007 — [code=php]
<?php
session_start();
if (!isset($_SESSION['email'])) {
mysql_connect("localhost" , "*****", "******") or die('Database is not responding.');
mysql_select_db("crescen9_Bandusers") or die('Unable to connect to database');
$query= "SELECT first_name, band_name, cdsalecount FROM Userinfo";
$result= mysql_query($query);
while ($row= mysql_fetch_assoc($result)) {
echo "Name :" . $row['first_name']} . "<br>" . "Band Name : " . $row['band_name'] . "<br>" . "CDs Sold To Date : " . $row['cdsalecount'] . "<br><br>";
}
} else {
print '<html><body bgcolor="#888888"><center><font size="2" face="verdana">You are not logged in! Click <a href="login.php">here to log in!<br>Don't have an account? <a href="bandusersignup.php">Sign Up Now!!!</a></font></center></body></html>';
}
?>[/code]
Copy linkTweet thisAlerts:
@tcsnguy07authorOct 29.2007 — Thanks for the help! I got past the first parse error, now it's sending me another one. mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource.

It looks like it's right. I tried encapsulating the $row=mysql_fetch_assoc before and i was getting the error, so thanks for fixing that, but can you find any other item in that specific line that needs to be fixed? Cause I went on php.net and looked up the proper syntax and it appears to be right. I'm hoping that by seeing what I have done wrong on this page I can fix all my other pages that are parsing wrong.

Thanks again.
Copy linkTweet thisAlerts:
@NogDogOct 29.2007 — It's telling you that your mysql_query() failed, most likely due to a syntax error or invalid identifier in your SQL. (mysql_query() returns a resource ID unless it fails, so when you use that result in another function which is expecting a MySQL resource ID but you are instead sending it a boolean FALSE, you get that error message. To do some quick debugging, change the query line to:
[code=php]
$result= mysql_query($query) or die("query failed ($query) " . mysql_error());
[/code]

Then if the query fails, you will see the query as it was actually sent to MySQL in the parentheses, followed by the error message returned by MySQL.
Copy linkTweet thisAlerts:
@tcsnguy07authorOct 30.2007 — Yeah I put in that argument to check what the problem was, and I found a couple errors like syntax in my database codes, but I fixed those. Now when I run the page, it either will come up with a mysql_fetch_array() not a valid resource on both of the lines where the fetch array is called on, or the page will come up totally blank. Here is a sample of the reduced down code that I am running to try to get it to work, and it still don't:

<?

session_start();

if (isset($email)) {

mysql_connect("localhost","*******","******")

or die('Could not connect');

mysql_select_db("*
**
*****");

$query1 = "SELECT *
FROM Userinfo WHERE email= '$email'";

$query2 = "SELECT cdsalecount from cdsalescount WHERE email= '$email'";

$result1 = mysql_query($query1);

$result2 = mysql_query($query2);

while ($row1 = mysql_fetch_array($result1)){

echo"<b>First Name:</b>" .$row1['first_name']."<br><br>" . "<b>Last Name:</b>" .$row1['last_name']."<br><br>".

"<b>Email (USER NAME):</b>" .$row1['email']."<br><br>"."<b>Address:</b>".$row1['address']."<br><br>"."<b>Phone:</b>" .$row1['phone']."<br><br>";

}

while ($row2 = mysql_fetch_array($result2)){

echo"<b>Total CD Sales To Date:</b>".$row2['cdsalecount'];

}

} else {

echo'Testing!';

}

?>
×

Success!

Help @tcsnguy07 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...