Jump to content

Register with Mysql


dustflower

Recommended Posts

HELLO!  :D

 

I got an error with my php file    and i  no its bound to  be a silly mistake as i am  prone to it

- i keep getting Parse error: syntax error, unexpected $end in C:\xampp\htdocs\registerTest.php on line 65

 

 

here is my code

 

 

 

<!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>
<h1>Register</h1>
<table><tr>
<form action="registerTest.php" method="post">

<td width="81">Username:</td>
<td width="247"><input name="username" size="30" autocomplete="off" 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>




</tr>
</table>


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


<?php
include 'mysql-connect.php';
$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];


$result = mysql_num_rows(mysql_query("SELECT * FROM users WHERE user_name='$username'"));
if($result == 1)
    {
    echo '<h1>ERROR!</h1>The username you have chosen already exists!';
    }
else
    {
    mysql_query("INSERT INTO users (user_name, password, userID")
VALUES ('$username', '$password', '$firstname');
    }
    
    echo '<p>Congratulations! You have successfully registered! </p>';
  <p>Click <a href="login.html">here</a> to login.</p>;

?>

 

if anyone could help then i will be greatly apperciate it !  Thanks  :D

Link to comment
https://forums.phpfreaks.com/topic/196898-register-with-mysql/
Share on other sites

The VALUES part should be included in the query string, like this

 

mysql_query("INSERT INTO users (user_name, password, userID) VALUES ('$username', '$password', '$firstname')");

 

You can make it easier to read by putting the query in a variable like

 

$sql = "INSERT INTO users (user_name, password, userID) VALUES ('$username', '$password', '$firstname')";
mysql_query($sql);

 

 

The reason you're getting the error is because you have HTML code inside PHP tags, look at this line:

 

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

 

You need to take it outside of the <?php  ?> tags

Link to comment
https://forums.phpfreaks.com/topic/196898-register-with-mysql/#findComment-1033713
Share on other sites

thanks cunoodle2 and  the182guy  ! i modified the codes and  even notice that i didn't  specify the  MySql connection

 

 

but i still have that error  plz help ! :'(


<!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>
<h1>Register</h1>
<table><tr>
<form action="registerTest.php" method="post">

<td width="81">Username:</td>
<td width="247"><input name="username" size="30" autocomplete="off" 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>




</tr>
</table>



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


<?php
define('DB_HOST', 'localhost');
	    define('DB_USER', 'root');
	    define('DB_PASSWORD', '');
    define('DB_DATABASE', 'login1');





$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}

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




$result = mysql_num_rows(mysql_query("SELECT * FROM users WHERE user_name='$username'"));
if($result == 1)
    {
    echo '<h1>ERROR!</h1>The username you have chosen already exists!';
    }
else
    {
    mysql_query("INSERT INTO users (user_name, password, userID)
VALUES ('$username', '$password', '$firstname')");
    }

    echo '<p>Congratulations! You have successfully registered! </p>';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/196898-register-with-mysql/#findComment-1033760
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.