Php 是否更新mysql数据库以及id和与id相关的图像?
我有这个php文件,它将更新mysql数据库中的一个表 它在一定程度上起作用。它将更新产品的名称(产品名称)和日期(添加日期)。但是它没有更新id,因此使用该id上载的图像不会显示 代码如下:Php 是否更新mysql数据库以及id和与id相关的图像?,php,mysql,Php,Mysql,我有这个php文件,它将更新mysql数据库中的一个表 它在一定程度上起作用。它将更新产品的名称(产品名称)和日期(添加日期)。但是它没有更新id,因此使用该id上载的图像不会显示 代码如下: <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string(
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['product_name'])) {
$product_name = mysql_real_escape_string($_POST['product_name']);
// See if that product name is an identical match to another product in the system
$sql = mysql_query("SELECT id FROM tomProduct WHERE product_name='$product_name' LIMIT 1");
$productMatch = mysql_num_rows($sql); // count the output amount
if ($productMatch > 0) {
echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="index.php">click here</a>';
exit();
}
// Add this product into the database now
$sql = mysql_query("UPDATE tomProduct SET product_name='$product_name', date_added=now()") or die (mysql_error());
$pid = mysql_insert_id();
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['fileField']['tmp_name'], "../tom/$newname");
header("location: verify_members.php");
exit();
}
?>
以下是表格:
<form action="verify_members.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">
<table width="90%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="right">Product Name</td>
<td width="80%"><label>
<input name="product_name" type="text" id="product_name" size="64" />
</label></td>
</tr>
<tr>
<td align="right">Product Image</td>
<td><label>
<input type="file" name="fileField" id="fileField" />
</label></td>
</tr>
<tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="button" id="button" value="Add This Item Now" />
</label></td>
</tr>
</table>
</form>
品名
产品形象
有人知道为什么会这样吗
谢谢
mysql\u insert\u id()
返回最后一条insert
记录,而不是UPDATE
为什么要使用UPDATE
将记录插入数据库?该更新查询会将所有product_name和date_added字段分别设置为$product_name
和now()
。我在任何地方都看不到实际的插入。不要在新代码()中使用mysql.*
函数,它们是。使用INSTEAD您正在调用mysql\u insert\u id()但实际上还没有插入任何内容?@kingkero,我知道,伙计,我只是在编写其他人的脚本。我已经告诉他们让我把脚本改成mysqli,但他们不想。所以这是他们的选择。那么我要用什么来代替呢?