gpt4 book ai didi

表单提交后PHP重定向到上传的页面?

转载 作者:行者123 更新时间:2023-11-30 23:20:24 25 4
gpt4 key购买 nike

在这个程序中,用户正在将照片上传到 MYSQL。 Photoid 是自动递增的。一旦用户提交表单,下面的代码就会采取行动。我希望用户被重定向到照片刚刚上传到的页面。我怎样才能将他重定向到 photopage.php?photoid=???

 $addaphoto_query = "INSERT INTO `photosite`.`photos` (id, photoid, title, description) VALUES ('$id', '', '$title', '$description')";

if ($run_addaphoto = mysqli_query($connect, $addaphoto_query){
header('Location: photopage.php?photoid=???');
}

最佳答案

您需要使用 PHP 函数 mysqli_insert_id() .这将为您提供带照片的 ID。

if ($run_addaphoto = mysqli_query($connect, $addaphoto_query){
header('Location: photopage.php?photoid=' . mysqli_insert_id());
}

如果您想知道,无论您获得多少流量,mysqli_insert_id() 都是安全的。 More reading on this SO question.

From the MySQL manual

For LAST_INSERT_ID(), the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client. It is not even changed if you update another AUTO_INCREMENT column with a nonmagic value (that is, a value that is not NULL and not 0). Using LAST_INSERT_ID() and AUTO_INCREMENT columns simultaneously from multiple clients is perfectly valid. Each client will receive the last inserted ID for the last statement that client executed.

关于表单提交后PHP重定向到上传的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15773839/

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