Parse Error Expecting ' or "

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AnsonM
Forum Commoner
Posts: 72
Joined: Thu Sep 25, 2003 7:21 am

Parse Error Expecting ' or "

Post by AnsonM »

Code: Select all

<?
session_start();
?>
<head>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<?php

	$db_connect = @mysql_connect('localhost', 'user', 'pass');
	// the "@" is used to supress the generic function error.
	if (!$db_connect) { // if value in variable is false (!)
    		die('Could not connect to MySQL database server, the server returned the error: '.mysql_error());
}
	$db = @mysql_select_db('dbname');
		if (!$db) { // if value in variable is false (!)
    		die('Could not select MySQL database, the server returned the error: '.mysql_error());
}

?>
<table width="100%">
	<tr>
		<td class="title"><b>Login to your admin account at 8th Dimension</b></td>
	</tr>
	<tr>
<?
if (!isset($HTTP_GET_VARS['do'])) {$do = "false";}
else {$do = $HTTP_GET_VARS['do'];}
if ($do == "false") {
?>
		<td class="content">
<table>
<form action="index.php?act=login&do=true" method="post">
	<tr><td>Username:</td><td><input type="text" name="uname"></td></tr>
	<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
	<tr><td></td><td><input type="submit" value=" Submit "></td></tr>
</form>
</table>
		</td>
<?
}
else {
$uname = $HTTP_POST_VARS['uname'];
$pass = $HTTP_POST_VARS['password'];

if ($uname == "" or $pass == "") {
	echo "Sorry, You haven't fully completed your information.  All fields are required.  Please go <a href="#" onClick="history.back(-1);">back</a> and re-enter your information.";}
else {
$sql = "select a_uname, a_pass from admins where a_uname = $uname and a_pass = $pass";
$sql = mysql_query($sql) or die(mysql_error());
$sql = mysql_num_rows($sql);
	if ($sql >= 1) {
		session_register("admin_8thd"); 
		$_SESSION["admin_uname"] = $HTTP_POST_VARS["uname"];
		echo "<font color="red">You have successfully logged in as $uname!</font>";}
	else {
?>
<table>
<font color="red">Your username and/or password was incorrect. Please try again. Your IP has been taken and the webmaster has been notified for security reasons.</font>
<form action="index.php?act=login&do=true" method="post">
	<tr><td>Username:</td><td><input type="text" name="uname"></td></tr>
	<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
	<tr><td></td><td><input type="submit" value=" send "></td></tr>
</form>
</table>
<? }} ?>
</center>
It says: Parse error: parse error, expecting `','' or `';'' in /home/eighth-d/public_html/admin/index.php on line 54

Line 54 is:

Code: Select all

<?php
		echo "<font color="red">You have successfully logged in as $uname!</font>";}
?>
Can someone please help!? :D
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Read the Strings section of the PHP Manual.

But, if you just want to fix your code, change line 54 to:

Code: Select all

<?php
      echo '<font color="red">You have successfully logged in as $uname!</font>';} // single quote (') in place of double (")
?>
Regards,
Scorphus.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I usually use all double quotes, and replace the quotes inside the echo quotes with \"

Example:

Code: Select all

echo "<font color="red">You have successfully logged in as $uname!</font>";}
Image Image
AnsonM
Forum Commoner
Posts: 72
Joined: Thu Sep 25, 2003 7:21 am

Post by AnsonM »

Thanx guys.. but theres another problem...

Code: Select all

<?
session_start();
?>
<head>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<?php

	$db_connect = @mysql_connect('localhost', 'eighth-d', 'mygame2468');
	// the "@" is used to supress the generic function error.
	if (!$db_connect) { // if value in variable is false (!)
    		die('Could not connect to MySQL database server, the server returned the error: '.mysql_error());
}
	$db = @mysql_select_db('eighth-d_8thd');
		if (!$db) { // if value in variable is false (!)
    		die('Could not select MySQL database, the server returned the error: '.mysql_error());
}

?>
<table width="100%">
	<tr>
		<td class="title"><b>Login to your admin account at 8th Dimension</b></td>
	</tr>
	<tr>
<?
if (!isset($HTTP_GET_VARS['do'])) {$do = "false";}
else {$do = $HTTP_GET_VARS['do'];}
if ($do == "false") {
?>
		<td class="content">
<table>
<form action="index.php?act=login&do=true" method="post">
	<tr><td>Username:</td><td><input type="text" name="uname"></td></tr>
	<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
	<tr><td></td><td><input type="submit" value=" Submit "></td></tr>
</form>
</table>
		</td>
<?
}
else {
$uname = $HTTP_POST_VARS['uname'];
$pass = $HTTP_POST_VARS['password'];

if ($uname == "" or $pass == "") {
	echo "Sorry, You haven't fully completed your information.  All fields are required.  Please go <a href="#" onClick="history.back(-1);">back</a> and re-enter your information.";}
else {
$sql = "select a_uname, a_pass from admins where a_uname = $uname and a_pass = $pass";
$sql = mysql_query($sql) or die(mysql_error());
$sql = mysql_num_rows($sql);
	if ($sql >= 1) {
		session_register("admin_8thd"); 
		$_SESSION["admin_uname"] = $HTTP_POST_VARS["uname"];
		echo "<font color="red">You have successfully logged in as $uname!</font>";}
	else {
?>
<table>
<font color="red">Your username and/or password was incorrect. Please try again. Your IP has been taken and the webmaster has been notified for security reasons.</font>
<form action="index.php?act=login&do=true" method="post">
	<tr><td>Username:</td><td><input type="text" name="uname"></td></tr>
	<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
	<tr><td></td><td><input type="submit" value=" send "></td></tr>
</form>
</table>
<? }} ?>
</center>
line 66 is the last line :?
AnsonM
Forum Commoner
Posts: 72
Joined: Thu Sep 25, 2003 7:21 am

Post by AnsonM »

oops forgot the error.. lol

Code: Select all

Parse error: parse error in /home/eighth-d/public_html/admin/index.php on line 66
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Line 45: Don't use 'or', use ||
Image Image
AnsonM
Forum Commoner
Posts: 72
Joined: Thu Sep 25, 2003 7:21 am

Post by AnsonM »

still gives the same error...

Code: Select all

<? 
session_start(); 
?> 
<head> 
<link rel="stylesheet" href="styles.css" type="text/css"> 
</head> 
<?php 

   $db_connect = @mysql_connect('localhost', 'eighth-d', 'mygame2468'); 
   // the "@" is used to supress the generic function error. 
   if (!$db_connect) { // if value in variable is false (!) 
          die('Could not connect to MySQL database server, the server returned the error: '.mysql_error()); 
} 
   $db = @mysql_select_db('eighth-d_8thd'); 
      if (!$db) { // if value in variable is false (!) 
          die('Could not select MySQL database, the server returned the error: '.mysql_error()); 
} 

?> 
<table width="100%"> 
   <tr> 
      <td class="title"><b>Login to your admin account at 8th Dimension</b></td> 
   </tr> 
   <tr> 
<? 
if (!isset($HTTP_GET_VARS['do'])) {$do = "false";} 
else {$do = $HTTP_GET_VARS['do'];} 
if ($do == "false") { 
?> 
      <td class="content"> 
<table> 
<form action="index.php?act=login&do=true" method="post"> 
   <tr><td>Username:</td><td><input type="text" name="uname"></td></tr> 
   <tr><td>Password:</td><td><input type="password" name="password"></td></tr> 
   <tr><td></td><td><input type="submit" value=" Submit "></td></tr> 
</form> 
</table> 
      </td> 
<? 
} 
else { 
$uname = $HTTP_POST_VARS['uname']; 
$pass = $HTTP_POST_VARS['password']; 

if ($uname == "" || $pass == "") { 
   echo "Sorry, You haven't fully completed your information.  All fields are required.  Please go <a href="#" onClick="history.back(-1);">back</a> and re-enter your information.";} 
else { 
$sql = "select a_uname, a_pass from admins where a_uname = $uname and a_pass = $pass"; 
$sql = mysql_query($sql) or die(mysql_error()); 
$sql = mysql_num_rows($sql); 
   if ($sql >= 1) { 
      session_register("admin_8thd"); 
      $_SESSION["admin_uname"] = $HTTP_POST_VARS["uname"]; 
      echo "<font color="red">You have successfully logged in as $uname!</font>";} 
   else { 
?> 
<table> 
<font color="red">Your username and/or password was incorrect. Please try again. Your IP has been taken and the webmaster has been notified for security reasons.</font> 
<form action="index.php?act=login&do=true" method="post"> 
   <tr><td>Username:</td><td><input type="text" name="uname"></td></tr> 
   <tr><td>Password:</td><td><input type="password" name="password"></td></tr> 
   <tr><td></td><td><input type="submit" value=" send "></td></tr> 
</form> 
</table> 
<? }} ?> 
</center>
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

There is nothing about using or instead of ||. You may continue using or anyway (Logical Operators). There is a missing } in your code. It was opened on line 41. Just close it on line 65:

Code: Select all

<? }}} ?>
Regards,
Scorphus.
Last edited by scorphus on Wed Oct 01, 2003 1:00 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you probably should pay more attention to the structure of your code.
Haven't checked the semantic of your script but at least with

Code: Select all

</table>
<?php }}} ?>
</center>
there are no parse errors anymore. Easier to catch when code's indented properly.

btw:
  • you shouldn't mix session_register() and $_SESSION, just use $_SESSION
  • not later than

    Code: Select all

    &lt;table&gt;
    &lt;font color="red"&gt;Your username and/or password was incorrect. Please try again. Your IP has been taken and the webmaster has been notified for security reasons.&lt;/font&gt;
    your html structure is broken. To avoid nasty sideeffects you should check this again
Post Reply