gpt4 book ai didi

php - (php) 无法从表中获取 id

转载 作者:行者123 更新时间:2023-12-01 00:18:49 25 4
gpt4 key购买 nike

<分区>

我有两个表,我想将数据添加到第一个表中,并从 first table 中获取新插入数据的 id 并使用它来将数据添加到第二张表

$statement = $dbh->prepare("INSERT INTO sis_university (name,site,tel,email,adress) VALUES (:name,:site,:tel,:email,:adress);");
if($statement->execute(array(':name' => $name,':site' => $site,':tel' => $tel,':email' => $email, ':adress' => $adress))){

$sql="SELECT id FROM sis_university WHERE site='$site' LIMIT 1";

$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$uniid = $row['id'];

$statement = $dbh->prepare("INSERT INTO sis_admin (username,password,name,tel,email,adress,type,universityid) VALUES (:username,:password,:name,:tel,:email,:adress,:type,:universityid);");
if($statement->execute(array(':username' => $username,':password' => $password,':name' => $adminname,':tel' => $admintel, ':email' => $adminemail, ':adress' => $adminadress, ':type' => $admintype, ':universityid' => $uniid))){
echo "success";
}else{
echo "failure" . " " . $uniid;
}
}else{
echo "failure";
}

数据已成功添加到第一个表中,但 $uniid 为空,数据未添加到第二个表中

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com