Few advices:
- separate mysql connection script in one file and include it in begining of each file where you need of it, don't write every time same connection script :
dbconnect.php
//Database Information
$dbhost = "localhost";
$dbname = "wings";
$dbuser = "user";
$dbpass = "pass";
//Connect to database
mysql_connect ("$dbhost","$dbuser","$dbpass")or die("Could not connect: ".mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
require_once('path/dbconnect.php')
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
If you want try this :
if ($name == "") {
echo "<p>You forgot to enter the name !!!";
exit;
}else if ($email == "") {
echo "<p>You forgot to enter the email !!!";
exit;
}else if ($username == "") {
echo "<p>You forgot to enter the username !!!";
exit;
}else if($username_exist > 0) {
echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
unset($username);
include 'registration.html';
exit();
}
$query = "INSERT INTO users (name, email, username, password) VALUES('$name', '$email', '$username', '$password')";
$result = mysql_query($query);
if ( !$result ) {
die("MySQl error" . mysql_errno() ." - ". mysql_error());
}
mysql_close();
header( "refresh:5;url=index.php" );
echo "You have successfully Registered. <br> You'll be redirected to home page in about 5 secs. If not, click <a href='wherever.php'>here</a>";
in login page, before to check user whether exist in DB, you must do :
......
$username = stripslashes($username);
$password = md5(stripslashes($password));
........
because, when user create account, you get inserted user password, calculate the md5 hash of a string and then insert to table. Therefore when user try to login you have to get inserted password, calculate the md5 hash and then check it:
.......
$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$password = md5($password);
$sql = "SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$result = mysql_query($sql);
...............
NOTE: You should declare your problem in section General Help or Newbies