This is for a realty website. Problem is that is creates the record for the property, but doesn't upload the graphic to the specified directory, or any directory for that matter.
I am running PHP 4.0 / Apache / mySQL on Win 98SE. I need the uploaded file to have the same ID as the record in the db.
Please help if you can!
<body>
<?php
// Add a listing to the database
?>
<form action="http://localhost:9000/sgr/add.php" method="post" enctype="multipart/form-data">
<p>Property Address:
<textarea name="address" rows="5" cols="40"></textarea>
<br>
Description:
<textarea name="description" rows="5" cols="40"></textarea>
<br>
Features:
<textarea name="features" rows="5" cols="40"></textarea>
</p>
<input type="file" name="userfile">
<p>
<input type="Submit" name="submitnew" value="Submit">
</p>
</form>
<?php
// Connect to the database
$dbconnect = @mysql_connect(
"localhost", "root", "");
if (!$dbconnect) {
echo( "Unable to connect");
exit();
}
// Select the database
if (! @mysql_select_db("sgr") ) {
echo( "Unable to locate the db");
exit();
}
// Request the ID of the record about to be created to
// assist in renaming the image file
$propertyselect = mysql_query("SELECT ID FROM property");
while ($propertyselection = mysql_fetch_array($propertyselect)) {
$id = $propertyselection["ID"];
$var = "propertyselection$id";
if ($$var) {
// assume you have captured the id for the image/DB record in var $id
$extension = ".jpg";
$saveto = "C:\nusphere\apache\nsdocs\sgr\images\" . $id . $extension;
copy($userfile, $saveto);
// If a property has been submitted add it to the database
$add = "INSERT IGNORE INTO property SET " .
"Address='$address', " .
"Description='$description', " .
"Features='$features'
$ID=$id";
// Verify addition of new property listing
$ok = mysql_query($add);
if ($ok) {
echo("<p>Added</p>");
} else {
echo("<p>Error</p>");
}
}
}
?>
</body>