PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password= ""; // Mysql password
$db_name="computershop"; // Database name
$tbl_name="login"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
session_start();
// username and password sent from form
$firstname = $_POST["firstname"]; //Stores the data into the variables
$lastname = $_POST["lastname"]; //Stores the data into the variables
$email = $_POST["email"]; //Stores the data into the variables
$myusername = $_POST["username"]; //Stores the data into the variables
$mypassword = md5($_POST["password"]); //encrypts the password that has been entered by the user
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' or email='$email'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
$row = mysql_fetch_row($result);
if($count==1){
$_SESSION["Error"]=true;
header("location:signup.php");//Sends the user back to the sign up page due to incorrect details
}
else {
//insert the values
$result= MYSQL_QUERY("INSERT INTO login (id, username, password, firstname, lastname, email)".
"VALUES ('NULL', '$myusername', '$mypassword', '$firstname', '$lastname', '$email')");
}
session_start();
$_SESSION["myusername"]=="";
session_destroy(); //clears sessions
?>
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.