Page 1 of 1
Parse Error Expecting ' or "
Posted: Tue Sep 30, 2003 11:19 pm
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!?

Posted: Tue Sep 30, 2003 11:28 pm
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.
Posted: Tue Sep 30, 2003 11:56 pm
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>";}
Posted: Wed Oct 01, 2003 12:09 am
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

Posted: Wed Oct 01, 2003 12:09 am
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
Posted: Wed Oct 01, 2003 12:13 am
by phice
Line 45: Don't use 'or', use ||
Posted: Wed Oct 01, 2003 12:37 am
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>
Posted: Wed Oct 01, 2003 12:55 am
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:
Regards,
Scorphus.
Posted: Wed Oct 01, 2003 12:57 am
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
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
<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>
your html structure is broken. To avoid nasty sideeffects you should check this again