如何获取用户表中创建的seeker_ID并将其添加到文档表中?有可能吗?
到目前为止,这是我的代码:
$link = mysqli_connect("localhost", "user", "password", "database");
$query = "INSERT INTO users (first_name, last_name) VALUES ('$FirstName','$LastName')";
$query = "INSERT INTO documents (seeker_ID, filename) VALUES ('','$filename')";
if (mysqli_multi_query($link, $query)) {
echo "Candidate ID: $seeker_id <br>";
echo "Candidate First Name: $FirstName <br>";
echo "Candidate Last Name: $LastName<br>";
echo "Email: $Email <br>";
echo "<br><br>Records added successfully - Refreshing In 5 Seconds<br>";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
答案 0 :(得分:0)
这不是很有帮助。首先,我要假设是MySQL。如果是这样,我建议使用PDO。
如果包含表单数据的请求是http GET或POST,您可以执行以下操作之一:
$seeker_ID = htmlentities($_GET["seeker_ID"]);
然后您可以使用该变量来构建查询。但请使用PDO:
$pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpass);
$stmt = $pdo->prepare("INSERT INTO documents(seeker_ID, filename) VALUES (:seeker_ID, :filename)");
$stmt->execute([
"filename" => $filename,
"seeker_ID" => $seeker_ID
]);