I want to use the MySQL_insert_id to get a value from first query which has an Auto-Increment with the name of PropertyImageID which is the last column in my properties table and also i have PropertyImageID same in my second table which is propertyimages first column and use it in second query for inserting the values in second table.
But its giving this error message:
Warning: mysql_insert_id() expects parameter 1 to be resource, Boolean given in on..line 31
here is my code (i didn't write the Auto-Increment Column in my query):
<?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>