拜托,我希望有人告诉我我的代码有什么问题,当我执行它时,数据库中没有任何反应。我不知道我的请求或其他问题。
我有一个名为远征的表格,包括列:ide,bordereau,agenceorig,nomexped,numexped,nomdestin,numdestin,destination emballage和valeur。
我有一张表格给我:$ bordereau,$ username,$ nomexped,$ numexped,$ nomdestin,$ numdestin,$ destination,$ emballage,$ valeur
当我使用按钮验证表单时,我检查$ bordereau是否已存在私有函数isexpedition($ bordereau),如果它不存在,我将数据插入表中。< / p>
当我执行代码时,我收到此消息: {&#34;错误&#34;:true,&#34;消息&#34;:&#34; Une erreur est survenue,veillez recomncer&#34;},显示数据尚未插入数据库
/*CRUD -> C -> CREATE*/
public function expedition($nomexped,$numexped,$nomdestin,$numdestin,$destination,$emballage,$bordereau,$valeur){
if($this-> isexpedition($bordereau)){
return 0;
}else{
$stmt = $this->con->prepare("INSERT INTO expedition (ide,bordereau,agenceorig,nomexped,numexped,nomdestin,numdestin,destination,emballage,valeur) VALUES (NULL,?,?,?,?,?,?,?,?,?)");
$stmt->bind_param("sssssssss",$Bordereau,$username,$Nomexped,$Numexped,$Nomdestin,$Numdestin,$Destination,$Emballage,$Valeur);
if($stmt->execute()){
return 1;
}else{
return 2;
}
}
}
private function isexpedition($bordereau){
$stmt = $this->con->prepare("SELECT ide FROM expedition WHERE bordereau=? ");
$stmt->bind_param("s",$bordereau);
$stmt->execute();
$stmt->store_result();
return $stmt->num_rows>0;
}
}
答案 0 :(得分:0)
$stmt = $conn->prepare("INSERT INTO users (username,password, email, gender) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $username, $password, $email, $gender);
//if the user is successfully added to the database
if($stmt->execute()){
//fetching the user back
$stmt = $conn->prepare("SELECT id, id, username, email, gender FROM users WHERE username = ?");
$stmt->bind_param("s",$username);
$stmt->execute();
$stmt->bind_result($userid, $id, $username, $email, $gender);
$stmt->fetch();
$user = array(
'id'=>$id,
'username'=>$username,
'email'=>$email,
'gender'=>$gender
);
$stmt->close();
//adding the user data in response
$response['error'] = false;
$response['message'] = 'User registered successfully';
$response['user'] = $user;
}