0
需要幫助這個PHP文件。我想發佈電子郵件,密碼,諾姆,endereco和telefone。後沒有得到Json的答覆後
首先驗證數據庫是否存在電子郵件和密碼(如果不插入)。
我不明白爲什麼JSON沒有反應。
<?php
include_once 'connection.php';
class User {
private $db;
private $connection;
function __construct() {
$this -> db = new DB_Connection();
$this -> connection = $this->db->getConnection();
}
public function does_user_exist($email,$password, $nome, $endereco, $telefone)
{
$query = "Select * from users where email='$email' and password = '$password' ";
$result = mysqli_query($this->connection, $query);
if(mysqli_num_rows($result)>0){
$json['success'] = ' Welcome '.$email;
echo json_encode($json);
mysqli_close($this -> connection);
}else{
$query = "insert into USERS (email, password, nome, endereco, telefone) values ('$email','$password', '$nome', '$endereco', '$telefone')";
$inserted = mysqli_query($this -> connection, $query);
if($inserted == 1){
$json['success'] = 'Acount created';
}else{
$json['error'] = 'Wrong password';
}
echo json_encode($json);
mysqli_close($this->connection);
}
}
}
$user = new User();
if(isset($_POST['email'],$_POST['password'],$_POST['nome'],$_POST['endereco'],$_POST['telefone'])) {
$email = $_POST['email'];
$password = $_POST['password'];
$nome = $_POST['nome'];
$endereco = $_POST['endereco'];
$telefone = $_POST['telefone'];
if(!empty($email) && !empty($password)){
$encrypted_password = md5($password);
$user-> does_user_exist($email,$password, $nome, $endereco, $telefone);
}else{
echo json_encode("you must type both inputs");
}
}
?>
這是我的連接文件也具有與配置與數據庫名密碼和用戶....
<?php
require_once 'config.php';
class DB_Connection {
private $connect;
function __construct() {
$this->connect = mysqli_connect(hostname, username, password, db_name)
or die("Could not connect to db");
}
public function getConnection()
{
return $this->connect;
}
}
?>
最簡單的事情就是確保在if和else中獲得'var_dumb($ json)'的位置。看看你在哪裏,你有什麼。另外,我希望那些是清潔的投入。由於您正在使用msqli_ *查看參數綁定。 – nerdlyist