我有两个表,分别是“采访”和“ personal_info”。我在将值插入数据库时遇到问题。我需要将txtTest,txtIntervieweddBy,txtRemarksDate,txtComment和txtRemarks的值插入到采访表中。 txtRemarksStatus的格式也相同,但是它的用途是更新另一个名为personal_info的表中的行。
<?php
include_once 'php/connection.php';
$connect = mysqli_connect("localhost", "root", "", "trackingsystemdb");
$number = count($_POST["txtIntervieweddBy"]);
if($number > 0)
{
for($i=0; $i<$number; $i++)
{
if(trim($_POST["txtIntervieweddBy"][$i] != ''))
{
$sql = "INSERT INTO interview (applicant_code, interviewed, dateInterviewed, comment, remarks) VALUES('".mysqli_real_escape_string($connect, $_POST["txtTest"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtIntervieweddBy"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtRemarksDate"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtComment"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtRemarks"][$i])."')";
}
}
}
$id = $_GET['id'];
$txtRemarksStatus=$_GET['txtRemarksStatus'];
$sql = "UPDATE personal_info SET status = '$txtRemarksStatus'
WHERE applicant_code = '$id'";
if (mysqli_multi_query($connect, $sql)) {
} else {
echo "Error ".mysqli_error($connect);
}
header('Location: addinterview.php?insert=sucess');
exit();
?>
答案 0 :(得分:0)
像这样使用它:-
include_once 'php/connection.php';
$connect = mysqli_connect("localhost", "root", "", "trackingsystemdb");
$number = count($_POST["txtIntervieweddBy"]);
if($number > 0)
{
for($i=0; $i<$number; $i++)
{
if(trim($_POST["txtIntervieweddBy"][$i] != ''))
{
$sql = "INSERT INTO interview (applicant_code, interviewed, dateInterviewed, comment, remarks) VALUES('".mysqli_real_escape_string($connect, $_POST["txtTest"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtIntervieweddBy"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtRemarksDate"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtComment"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtRemarks"][$i])."')";
mysqli_query($connect, $sql);
}
}
}
$id = $_GET['id'];
$txtRemarksStatus=$_GET['txtRemarksStatus'];
$sql = "UPDATE personal_info SET status = '$txtRemarksStatus'
WHERE applicant_code = '$id'";
if (mysqli_query($connect, $sql)) {
} else {
echo "Error ".mysqli_error($connect);
}
header('Location: addinterview.php?insert=sucess');
exit();