我只是编程中的新手,我不知道我的代码中存在什么问题。我在tblins中输入的数据被记录下来,但tbluser中的数据不会出现在我的数据库中。但是当我尝试删除我的tblins的插入查询时,我想要在tbluser中输入的数据可以记录在我的数据库中。我应该怎么做才能让我的两个表格可以记录我在页面中点击提交后所输入的所有数据?谢谢。php sql插入表
$usr="INSERT INTO tbluser(username,password,type) VALUES('".$_POST['txtuname']."','".$_POST['txtpass']."','".$_POST['type']."')";
$ins="INSERT INTO tblins(insLN,insFM,insMN,insadd,insCN,insemail,insbdate) VALUES('".$_POST['txtLN']."','".$_POST['txtFN']."','".$_POST['txtMN']."','".$_POST['txtadd']."','".$_POST['txtCN']."','".$_POST['txtemail']."','".$bdate."')";
感谢所有的建议先生。 :D我目前准备好什么SQL注入。希望了解更多。 :D
这是我的完整代码。
<?php
include("connect.php");
if(isset($_POST['txtpass']) && isset($_POST['txtrepass'])){
$password1=mysql_real_escape_string($_POST['txtpass']);
$password2=mysql_real_escape_string($_POST['txtrepass']);
if($password1==$password2){
$typeopt=$_POST['type'];
$bdate=$_POST['year']."-".$_POST['month']."-".$_POST['day'];
switch($typeopt){
case 'ins':
$usr=mysql_query("INSERT INTO tbluser(username,password,type) VALUES('".$_POST['txtuname']."','".$_POST['txtpass']."','".$_POST['type']."')");
$ins=mysql_query("INSERT INTO tblins(insLN,insFM,insMN,insadd,insCN,insemail,insbdate) VALUES('".$_POST['txtLN']."','".$_POST['txtFN']."','".$_POST['txtMN']."','".$_POST['txtadd']."','".$_POST['txtCN']."','".$_POST['txtemail']."','".$bdate."')");
if(mysqli_query($con,$ins)) {
echo"success";
}
else{
echo"fail to register";
}
break;
case 'student':
$std="INSERT INTO tblstudent(studLN,studFN,studMN,studBDate,studemail,studadd,studCN)";
$usr="INSERT INTO tbluser(username,password,type)";
$usr=$usr."VALUES('".$_POST['txtuname']."',";
$usr=$usr."'".$_POST['txtpass']."',";
$usr=$usr."'".$_POST['type']."')";
$std=$std."VALUES('".$_POST['txtLN']."',";
$std=$std."'".$_POST['txtFN']."',";
$std=$std."'".$_POST['txtMN']."',";
$std=$std."'".$bdate."',";
$std=$std."'".$_POST['txtemail']."',";
$std=$std."'".$_POST['txtadd']."',";
$std=$std."'".$_POST['txtCN']."')";
if(mysqli_query($con,$std)) {
echo"success";
}
else{
echo"fail to register";
}
}
}
else{
echo"<form>";
echo "Password doesn't match. Try registering again.";
echo "<input type=submit formaction=register.php value=back>";
echo"</form>";
}
}
?>
你可以在你试图将这些代码写入数据库的地方添加代码吗? – andrewsi
你应该检查任何PHP错误或MySQL错误。有可能有一个错误信息告诉你*确切的*有什么问题。另外,你的代码对SQL注入攻击是全面的。你需要阅读和理解这个:http://php.net/manual/en/security.database.sql-injection.php – David
这应该是你的数据库连接错误。在这里粘贴你的完整代码 –