我试图插入两个不同的表,但最后一个表没有收到数据。 显示没有错误我真的不知道这种情况可能是什么原因。 是因为第二个表包含外键吗?
<?php
#connect to the db
require_once('db.inc.php');
?>
<?php
$date_created = date('y-m-d h:i:s a');
$username = (isset($_POST['username'])) ? trim($_POST['username']) : '';
$Previllage = (isset($_POST['Previllage'])) ? trim($_POST['Previllage']) : '';
#second tanble values
$title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
$firstname = (isset($_POST['firstname'])) ? trim($_POST['firstname']) : '';
$lastname = (isset($_POST['lastname'])) ? trim($_POST['lastname']) : '';
$client_code = (isset($_POST['client_code'])) ? trim($_POST['client_code']) : '';
#end
$query = "INSERT INTO tish_user(username,Previllage,date_created)
VALUES(:username,:Previllage,:date_created)";
$insert = $con->prepare($query);
$insert->execute(array(':username' => $username,
':Previllage' => $Previllage,
'date_created' => $date_created));
# try another insert
$query = "INSERT INTO tish_clientinfor(title,firstname,lastname,client_code,date_registered)
VALUES(:title,:firstname,:lastname,:client_code,:date_registered)";
$insert = $con->prepare($query);
$insert->execute(array(
':title' => $title,
':firstname' => $firstname,
':lastname' => $lastname,
':client_code' => $client_code,
'date_registered' => $date_created));
?>
答案 0 :(得分:0)
如果第二个查询中的“client_code”字段具有外键约束,那么我认为这是导致查询失败的原因。您可以尝试回显第二个查询并在phpmyadmin sql部分或mysql命令提示符中运行它。