Jump to content

typo??


WSparrow

Recommended Posts

Hi guys,

 

I'm trying to make a basic registration page on a LAMP server.  The page loads fine but after filling in the fields and hitting 'submit' it returns a blank page.  The page source is also blank.  I know it's not the server setup because other php pages load fine.  Can anybody see a problem with my code?  (It's in two files .php and .html)  It's probably something stupidly simple but I've been staring at this for about 5 hours now and I'm starting to go cross-eyed.

 

register.php:

 

<?php

 

include 'mysql-connect.php';

 

$username = $_POST['username'];

 

$password = $_POST['password'];

 

$firstname = $_POST['firstname'];

 

$lastname = $_POST['lastname'];

 

$email = $_POST['email'];

 

 

 

$result = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE username='$username'"));

 

if($result == 1)

 

        {

 

        echo '<h1>ERROR!</h1>The username you have chosen already exists!';

 

        }

 

else

 

        {

 

        mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email)

 

VALUES ('$username', '$password', '$firstname', '$lastname', '$email')");

 

 

 

        echo '

 

  <p>Congratulations! You have successfully registered! </p>

 

  <p>Click <a href="login.php">here</a> to login.</p>';

 

?>

 

 

register.html:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

 

<title>Register</title>

 

</head>

 

 

 

<body background="Paper.JPG">

 

<h1>Register</h1>

 

<form action=register.php method=post>

 

<table><tr>

 

 

 

 

 

<td width="81">Username:</td>

 

<td width="247"><input name="username" size="30" value="" type="text" /></td>

 

 

 

</tr><tr>

 

 

 

<td>Password:</td>

 

<td><input name="password" size="30" type="password" /></td>

 

 

 

</tr>

 

 

 

<tr>

 

 

 

<td>First Name:</td>

 

<td><input name="firstname" size="30" type="text" /></td>

 

 

 

</tr>

 

 

 

<tr>

 

 

 

<td>Last Name:</td>

 

<td><input name="lastname" size="30" type="text" /></td>

 

 

 

</tr>

 

 

 

<tr>

 

 

 

<td>Email:</td>

 

<td><input name="email" size="30" maxlength="100" /></td>

 

 

 

</tr>

 

</table>

 

 

 

 

 

<p><input type="submit" class="button" value="Register" /></p>

 

</form>

 

</body>

 

</html>

 

 

THANKS

Link to comment
https://forums.phpfreaks.com/topic/223997-typo/
Share on other sites

if($result == 1) {
echo '<h1>ERROR!</h1>The username you have chosen already exists!';
} else {
mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) VALUES ('$username', '$password', '$firstname', '$lastname', '$email')");
echo '<p>Congratulations! You have successfully registered! </p><p>Click <a href="login.php">here</a> to login.</p>';
} // missing bracket.

Link to comment
https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157565
Share on other sites

I'm using gedit. 

Can't try these things as fast as you guys are posting them lol

 

okay the full error it gave me is:

 

PHP Parse error:  syntax error, unexpected T_ECHO in /var/www/html/www.***.com/register.php on line 21, referer: http://www.***.com/register.html

 

error_reporting(E_ALL);
<?php

include 'mysql-connect.php';

$username = $_POST['username'];

$password = $_POST['password'];

$firstname = $_POST['firstname'];

$lastname = $_POST['lastname'];

$email = $_POST['email'];



$result = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE username='$username'"));

if($result == 1)

        {

        echo '<h1>ERROR!</h1>The username you have chosen already exists!';

        }

else

        {

        mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) 

VALUES ('$username', '$password', '$firstname', '$lastname', '$email')"




        echo '

  <p>Congratulations! You have successfully registered! </p>

  <p>Click <a href="login.php">here</a> to login.</p>';

}

?>

 

@bluesky

I'll try that now.

Link to comment
https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157574
Share on other sites

It is outside of the double quote.  The current edit of the file (which is getting the parse error at the semi-colon) is:

 

error_reporting(E_ALL);

<?php

include 'mysql-connect.php';

$username = $_POST['username'];

$password = $_POST['password'];

$firstname = $_POST['firstname'];

$lastname = $_POST['lastname'];

$email = $_POST['email'];



$result = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE username='$username'"));

if($result == 1) {

        echo '<h1>ERROR!</h1>The username you have chosen already exists!';

} else {

        mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) 

VALUES ('$username', '$password', '$firstname', '$lastname', '$email')";

}	



        echo '

  <p>Congratulations! You have successfully registered! </p>

  <p>Click <a href="login.php">here</a> to login.</p>';

}

?>

 

I did notice that the html was ISO and the php was UTF so I changed it so they're both using utf-8, but that didn't make any difference.

Link to comment
https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157614
Share on other sites

maybe this?

 

<?php
error_reporting(E_ALL);

require_once('mysql-connect.php');

$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];

$result = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE username='$username'"));

if($result == 1)
{
echo '<h1>ERROR!</h1>The username you have chosen already exists!';
}
else
{
mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) VALUES ('$username', '$password', '$firstname', '$lastname', '$email')");
echo "<p>Congratulations! You have successfully registered!</p><br><p>Click <a href=\"login.php\">here</a> to login.</p>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157635
Share on other sites

The closing parenthesis on that line belongs outside of the closing double quote . . .

 

the problem is missing closing paren in the mysql_query() call.

 

mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) 
VALUES ('$username', '$password', '$firstname', '$lastname', '$email')");

Link to comment
https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157637
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.