我想使用MySQL_insert_id从第一个查询中获取一个值,该查询具有一个名为PropertyImageID的自动增量,这是我的属性表中的最后一列,并且我的第二个表中的PropertyImageID相同,即propertyimages的第一列并使用它在第二个查询中插入第二个表中的值。
但它给出了这个错误信息:
警告:mysql_insert_id() 期望参数 1 是资源,布尔值在 on..line 31
这是我的代码(我没有在查询中编写自动增量列):
<?php
require_once('db.php');
@$PropertyName=$_POST['pname'];
@$PropertyStatus=$_POST['pstatus'];
@$PropertyID=$_POST['propertyid'];
if(isset($_FILES['file_upload']))
{
$propertyquery="INSERT INTO properties(PropertyID, PropertyName, PropertyStatus)
VALUES('$PropertyID', '$PropertyName', '$PropertyStatus')";
$propertyqueryrun=mysql_query($propertyquery) or die(mysql_error());
if($propertyqueryrun)
{
echo '<br><br> The Property Information Insertion was Successfully';
}
else
{
echo '<br><br> Property Insertion Failed';
}
$shuff=str_shuffle("ABD6565LSLFKDSAJFD");
mkdir("upload/$shuff");
$files=$_FILES['file_upload'];
for($x = 0; $x < count($files['name']); $x++)
{
$name=$files['name'][$x];
$tmp_name=$files['tmp_name'][$x];
if(move_uploaded_file($tmp_name, "upload/$shuff/".$name))
{
$result=mysql_query($propertyquery)------>First query;
$id=mysql_insert_id($result) or die(mysql_error());
$imagequery="INSERT INTO propertyimages(PropertyImageID, ImageName,
ImagePath) VALUES('**$id**', '$name', 'upload/$name')";
$imagequeryrun=mysql_query($imagequery);
echo 'Image '. $name .' Uploaded Successfully <br>';
}
else
{
echo 'uploading images failed failed';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<label>PropertyName:<br /></label>
<input type="text" name="pname" /><br />
<label>PropertyStatus:<br /></label>
<input type="text" name="pstatus" /><br />
<label>PropertyID:<br /></label>
<input type="text" name="propertyid" /><br />
<input type="file" name="file_upload[]" multiple="multiple" / size="7"><br /><br />
<input type="submit" value="Submit Form" />
</form>
<a href="home.php">Display Images</a>
</body>
</html>