我有两个表,名为interview和personal_info。我在数据库中插入值时遇到问题。我需要在interview表中插入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();
?>发布于 2018-08-01 15:15:32
像这样使用它:
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();https://stackoverflow.com/questions/51624374
复制相似问题