class register{
private $host; //The host address
private $user; //The user
private $pass; //The password
private $database; //The database
//Connect with the database
function __construct(){
$host = $this -> host;
$user = $this -> user;
$pass = $this -> pass;
// $database = $this -> database;
// echo $db;
$conn = mysql_connect($host,$user,$pass);
$db = mysql_select_db($this -> database,$conn);
// if($conn){
// echo "连接成功";
// }else{
// echo "连接失败";
// }
if($db){
echo "数据库成功";
}else{
echo "数据库失败";
}
}
//Add a user
function addUser(){
$dataObj = $_POST["dataObj"];
$userInfo = json_decode($dataObj,true); //change the data from the type of json to array.
$username = $userInfo[0];
$password = $userInfo[1];
$repassword = $userInfo[2];
//The sql to add the new user
@$sql_addUser = <<
insert into users values("","$username","$password","$repassword");
EOF;
// var_dump($sql_addUser);break;
$result = mysql_query($sql_addUser);
// var_dump($result);break;
if($result){
echo 1;
}else{
echo 0;
}
}
}
// echo addUser();
$register = new register("localhost","root","","hotel");
$register -> addUser();
// break;
?>
展开