我尝试singer id
在另一个表中插入数据后生成,当我使用准备语句时出现问题:
警告:mysqli_insert_id() 期望参数 1 为 mysqli,对象 > 在 /Applications/XAMPP/xamppfiles/htdocs/admin/singer.php 中给出 > 第 22 行警告:mysqli::prepare() [mysqli.prepare]: couldn' t fetch > mysqli in /Applications/XAMPP/xamppfiles/htdocs/admin/singer.php on > line 24
<?php
include('../db_inc.php');
$singer_name =$_POST['singer_name'];
$singer_gender=$_POST['singer_gender'];
$singer_des=$_POST['singer_description'];
$singer_genre=$_POST['genre_list'];
if($stmt=$connection->prepare("INSERT INTO singers(singer_name,singer_gender,singer_description) VALUES (?,?,?)")){
$stmt->bind_param('sss',$singer_name,$singer_gender,$singer_des);
$result1=$stmt -> execute();
$singer_id=mysqli_insert_id($stmt);
$stmt->close();
}
if($stmt2=$connection->prepare("INSERT INTO genre_singer(f_singer_id,f_genre_id) VALUES (?,?)")){
$stmt2->bind_param('fs',$singer_id,$singer_genre);
$result2=$stmt2 -> execute();
$stmt2->close();
$connection->close();
}
if($result1 & $result2){
echo "insert successfully";
};
?>