我试图将数据插入到合规表,该列名为auditee这不是主键。检索来自特定列的特定数据
所以数据录入后。我想根据“受审核方”检索数据
我应该在MySQL中插入数据到多个表(合规表& auditee_details表)还是任何想法?
<?php
// Create connection
$con=mysqli_connect("localhost","root","","mtt_iem");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$a = $_POST['date'];
$b = $_POST['block'];
$c = $_POST['module'];
$d = $_POST['auditor'];
$e = $_POST['sw_score'];
$f = $_POST['sw_comment'];
$g = $_POST['dm_score'];
$h = $_POST['dm_comment'];
$i = $_POST['uniform_score'];
$j = $_POST['uniform_comment'];
$k = $_POST['totalscore'];
$l = $_POST['auditorcomment'];
$m = $_POST['auditee'];
$sql = "INSERT INTO compliance_module
(date,block,module,auditor,sw_score,sw_comment,dm_score,dm_comment,uniform_score,uniform_comment,totalscore,auditorcomment,auditee) ".
"VALUES ('$a','$b','$c','$d','$e','$f','$g','$h','$i','$j','$k','$l','$m')";
$result = mysqli_query($con,$sql);
?>
您的代码容易受到SQL注入,就需要解决这个问题。 – Enstage
好像你所要求的是:'select * from compliance_module WHERE auditee ='foo'' – rtfm
你需要使用mysqli_escape来转义你的数据值(或者更好地使用参数化查询)。否则,人们可以将SQL发布到您的表单并窃取您的数据/破坏您的数据库。另外,使用$ a,$ b,$ c等等是不必要的,只会让你的代码感到困惑和冗长。如果你想(但不需要,你需要首先转义它),你可以在字符串中使用$ _POST [auditee](当你在一个字符串中使用它的时候没有引号)。 – Cuagau