作者:曾静ZHH_423 | 来源:互联网 | 2023-09-16 14:45
Imtryingtomakeawebsiteinwhichauserinputsdetailsononescreen,andtheyarepostedonto
I'm trying to make a website in which a user inputs details on one screen, and they are posted onto the following script. This script is meant to store these details in a database along with a unique integer ID (which it does), and then generate two links containing the unique ID of the record just created. Since the database creates the ID rather than the page before, I've tried to query the database for the most recent record (i.e. the one with the highest unique ID value) and use that number in the link, however with the current script the ID doesn't seem to show up in the page. Is it a variable type thing? Is there a simpler way to get the ID of the page just created? Here's the code:
我正在尝试建立一个用户在一个屏幕上输入详细信息的网站,并将它们发布到以下脚本中。此脚本用于将这些详细信息与唯一的整数ID(它执行)一起存储在数据库中,然后生成包含刚刚创建的记录的唯一ID的两个链接。由于数据库之前创建的是ID而不是页面,我试图在数据库中查询最新的记录(即具有最高唯一ID值的记录)并在链接中使用该数字,但是使用当前脚本ID似乎没有显示在页面中。这是一个变量型的东西吗?有没有更简单的方法来获取刚刚创建的页面的ID?这是代码:
$css = $_POST['css'];
$shopName = strip_tags($_POST['title']);
$email = $_POST['email'];
$con = mysql_connect("***","***","***");
if (!$con)
{
die('Could not connect to database: '. mysql_error());
}
mysql_select_db("***", $con);
$sql = "INSERT INTO wps_Shops (shopName, shopEmail, shopStyle)
VALUES ('$shopName', '$email', '$css')";
$quer = mysql_query($sql);
$result = mysql_query("SELECT *
FROM wps_Shops
ORDER BY shopId DESC
LIMIT 1");
$lastShop = mysql_fetch_array($result);
$id = strval($lastShop['id']);
echo ("Id: ".$id);
if ($quer)
{
echo("Shop created
");
echo("Go to shop
");
echo("Add products
");
}
mysql_close($con);
4 个解决方案