Valhalla Legends Forums Archive | Web Development | Parse Error in code on line 38

AuthorMessageTime
Chronix
I get a parse error on line 38 when I run this script, yet it runs fine on my other pages. Also, the page will work properly if the php code is taken out, so I'm not really sure what to make of this error.

[code]
<?php
mysql_connect("localhost","brian","password") or die (mysql_error());
mysql_select_db("user_login") or die (mysql_error());

if(isset($_COOKIE['ID_my_site']))

{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die (mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{

<b>Enter Project Information - Return <a href="home.php">home</a>.</b>

<br><br>

<pre>
<form action="insert_project_info.php" method="post">
Project Number:      <input type="text" name="projectnumber" /><br>
Project Name:        <input type="text" name="projectname" /><br>
Client Name:        <input type="text" name="clientname" /><br>
Client Address:      <input type="text" name="clientaddress" /><br>
Client Office Phone: <input type="text" name="clientofficephone" /><br>
Client Fax:          <input type="text" name="clientfax" /><br>
Client Cell:        <input type="text" name="clientcell" /><br>
Client Email:        <input type="text" name="clientemail" /><br>
<input type="submit" value="Submit" /> <input type="reset" value="Clear" />
</form>
</pre>

}
?>
[/code]
February 19, 2008, 10:27 PM
Barabajagal
You did it wrong. (You can't just put HTML into PHP like that!)
February 19, 2008, 10:39 PM
Chronix
Well I'm not sure exactly what I've done wrong, since after all, the script works fine on all of my other pages. Any suggestions as to what changes should be made?
February 19, 2008, 10:41 PM
Chronix
Well it's done here on my login page, same concept. So I'm not sure what I did different. Could you point me in the right direction as far as what changes need to be made to my source?

[code]
<?php
mysql_connect("localhost","brian","password") or die (mysql_error());
mysql_select_db("user_login") or die (mysql_error());

if(isset($_COOKIE['ID_my_site']))

{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die (mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header("Location: home.php");

}
}
}

if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) { die ('You did not fill in a required field.'); }

if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']); }
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'") or die (mysql_error());

$check2 = mysql_num_rows($check); if ($check2 == 0) { die ('That user does not exist in the database. <a href="register.php">Click here to register</a>'); }
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);

if ($_POST['pass'] != $info['password']) { die ('Incorrect password, please try again.'); }

else
{

$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);

header("Location: home.php");
}
}
}
else
{

?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h1>Login</h1></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
<?php
}
?>
[/code]
February 19, 2008, 10:47 PM
BreW
[quote author=Andy link=topic=17337.msg176533#msg176533 date=1203460788]
You did it wrong. (You can't just put HTML into PHP like that!)
[/quote]
Sure he could, it just needs to be outside of the <? ?> braces.
February 19, 2008, 11:00 PM
Barabajagal
<? and ?> denote php starting and ending. What you just said was retarded brew. GTFO.

ChroniX, notice how on the code you just pasted, you end the PHP section before the HTML starts?
February 19, 2008, 11:16 PM
Chronix
First of all, brew, <? and?> isn't the proper way to begin and end a php script, <?php //code ?> is.  :)

Andy, thank you for pointing that out.
February 19, 2008, 11:21 PM
BreW
[quote author=Andy link=topic=17337.msg176537#msg176537 date=1203462961]
<? and ?> denote php starting and ending. What you just said was retarded brew. GTFO.
[/quote]
No, <? and ?> are the brackets in which the code must be. Anything else not in those would be sent to the client as-is. anotherwords, you could put raw html, as long as it is around the brackets. thanks.
@Chronix: Isn't it funny how <? works just as well? I wonder why. And do you honestly think you need to add //code.....? That's what they call a comment.
February 19, 2008, 11:33 PM
Chronix
brew, I said using <?php to begin a script is the proper way to use it, although I'm not in denial against your method of beginning with <?, it works as well. So I never said you were wrong, I was simply pointing out the proper way to use the tags. As for the //code, that was to refer to whatever is being put inside the script, which in that case, nothing at all. It was simply an example. GFY.
February 19, 2008, 11:39 PM
Barabajagal
It only works if you configure php.ini to allow short opening tags. Give up, brew.
February 20, 2008, 12:05 AM
BreW
[quote author=Andy link=topic=17337.msg176542#msg176542 date=1203465946]
It only works if you configure php.ini to allow short opening tags. Give up, brew.
[/quote]

In that case, every web server i've put a script on that uses <? must have it configured so.
Give up what? I don't see what there is to give up on? Unless this is your idea of a 'game'... It's funny how defensive you get when someone says something contrary to your own word.

Chronix: GFY to you too!.
February 20, 2008, 12:13 AM
Barabajagal
Give up your pointless arguing.
February 20, 2008, 12:36 AM
Chronix
He's trolling, we must not feed him! :)
February 20, 2008, 10:12 PM
dlStevens
lol.

I have to say this was probably the worst thread I've ever seen go from a question to a retarded argument.
February 21, 2008, 12:08 AM

Search