0

我正在尝试插入两个不同的表,但最后一个表没有收到数据。没有显示错误我真的不知道这种情况可能是什么原因。是因为第二个表包含外键吗?

<?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));
?>
4

1 回答 1

0

如果第二个查询中的“client_code”字段具有外键约束,那么我相信这就是导致查询失败的原因。您可以尝试回显第二个查询并在 phpmyadmin sql 部分或 mysql 命令提示符中运行它。

于 2013-01-27T09:05:17.707 回答