试图在一个php文件中写两个语句使用准备好的语句,我在一个php文件中创建两个语句...这是我的php文件...
<?php
require("config.inc.php");
if (!empty($_POST)) {
if (empty($_POST['name'])|| empty($_POST['password'])) {
$response["success"] = 0;
$response["message"] = "Please Enter Both a Username and Password.";
die(json_encode($response));
}
$query = " SELECT 1 FROM nama WHERE name= :name";
$query_params = array(
':name' => $_POST['name']
);
$queryT = " SELECT 1 FROM ProfilSiswa WHERE nama_lengkap= :nameT";
$query_paramsT = array(
':nameT' => $_POST['nama_lengkap']
);
try {
// These two statements run the query against your database table.
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$stmtT = $db->prepare($queryT);
$resultT = $stmt->execute($query_paramsT);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error1. Please Try Again!";
die(json_encode($response));
}
$query = "INSERT INTO nama(name, info) VALUES ( :name, :info) ";
$queryT = "INSERT INTO ProfilSiswa(nama_lengkap) VALUES ( :nameT) ";
$query_params = array(
':name' => $_POST['name'],
':info' => $_POST['info']
);
$query_paramsT = array(
':nameT' => $_POST['nama_lengkap']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$stmtT = $db->prepare($queryT);
$resultT = $stmt->execute($query_paramsT);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error2. Please Try Again!";
die(json_encode($response));
}
...
当我使用该语句时,值不会插入到表中,并且在尝试执行时不显示错误...
答案 0 :(得分:0)
您的代码存在问题
$stmtT = $db->prepare($queryT);
$resultT = $stmt->execute($query_paramsT);
应该是
$stmtT = $db->prepare($queryT);
$resultT = $stmtT->execute($query_paramsT);