下面的代码将一些数据插入MySQL数据库。我想在插入后将页面加载到此记录,但我正在尝试加载的变量($ insert)未在标题上显示。有人可以帮忙吗?
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO riders (firstname,secondname,email,mobile,landline,dob,addressline1,town,county,postcode) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$q = $pdo->prepare($sql);
$q->execute(array($firstname,$secondname,$email,$mobile,$landline,$dob,$streetaddress,$town,$county,$postcode));
$insert = mysql_insert_id();
Database::disconnect();
header("Location:read.php?id=.$insert");
答案 0 :(得分:1)
使用$pdo->lastInsertId()
获取SQL插入后的最后一个ID。