<?php
session_start();
include ("mysql_connect.php");
$user = $_POST["username"];
$pass = $_POST["password"];
$nick = $_POST["nickname"];
$depart = $_POST["department"];
if(empty($user)){
echo "<script>alert('Please input your username');window.location = 'register.php';</script>";
exit();
}
if(empty($pass)){
echo "<script>alert('Please input your password');window.location = 'register.php';</script>";
exit();
}
if(empty($nick)){
echo "<script>alert('Please input your nickname');window.location = 'register.php';</script>";
exit();
}
if(empty($depart)){
echo "<script>alert('Please input your choose department');window.location = 'register.php';</script>";
exit();
}
$user_check = mysql_query("SELECT username FROM member WHERE username ='$user'");
$do_user_check = mysql_num_rows($user_check);
if($do_user_check >0){
die("Username is already in use!");
}
$sql = "INSERT INTO member SET username='$user' , password='$pass' , nickname='$nick' id_department='$depart'";
$dbQuery = mysql_query($sql);
if($dbQuery){
echo "Save Done";
}else{
echo "Error Save".$sql;
}
?>
mysql_connect.php Code (PHP)
<?php
@mysql_connect("localhost", "root", "") or die ("error connect to database");
@mysql_select_db("report") or die ("error select db");
mysql_query("SET NAMES 'tis620' ");
?>