I am a nood forgive me if all my code is messy, and evrything I know is self taught so my knowledge is not that great.
I have an issue, I created an insert record form and in it there is title, price, 8 file upload fields and other fields.
every thing somewhat works fine, but the file upload has problems.
if I input images into all the 8 file fields and submit the form there is no problem, but if i input 7 or 6 or less, i.e leave one or more file field blank and then try to submit the form, I get an error message (Notice: Undefined variable: insertSQL ...... line 126, Query was empty) and line 126 is
$Result1 = mysql_query($insertSQL, $val_nija_estate) or die(mysql_error());
I am using dreamweaver
And I m not so keen on using the blob method of uploading, i want to save the images on the server.
this is the code for the whole thing
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add_listing")) {
$name = basename($_FILES['pro_image_1']['name']);
$ext = substr(strrchr($name, "."), 1);
$randName = md5(rand() * time());
$finalfile1 = $randName . '.' . $ext;
$t_name = $_FILES['pro_image_1']['tmp_name'];
$dir = '../../images/properties/images/';
if(move_uploaded_file($t_name,$dir."/".$finalfile1))
$name = basename($_FILES['pro_image_2']['name']);
$ext = substr(strrchr($name, "."), 1);
$randName = md5(rand() * time());
$finalfile2 = $randName . '.' . $ext;
$t_name = $_FILES['pro_image_2']['tmp_name'];
$dir = '../../images/properties/images/';
if(move_uploaded_file($t_name,$dir."/".$finalfile2))
$name = basename($_FILES['pro_image_3']['name']);
$ext = substr(strrchr($name, "."), 1);
$randName = md5(rand() * time());
$finalfile3 = $randName . '.' . $ext;
$t_name = $_FILES['pro_image_3']['tmp_name'];
$dir = '../../images/properties/images/';
if(move_uploaded_file($t_name,$dir."/".$finalfile3))
$name = basename($_FILES['pro_image_4']['name']);
$ext = substr(strrchr($name, "."), 1);
$randName = md5(rand() * time());
$finalfile4 = $randName . '.' . $ext;
$t_name = $_FILES['pro_image_4']['tmp_name'];
$dir = '../../images/properties/images/';
if(move_uploaded_file($t_name,$dir."/".$finalfile4))
$name = basename($_FILES['pro_image_5']['name']);
$ext = substr(strrchr($name, "."), 1);
$randName = md5(rand() * time());
$finalfile5 = $randName . '.' . $ext;
$t_name = $_FILES['pro_image_5']['tmp_name'];
$dir = '../../images/properties/images/';
if(move_uploaded_file($t_name,$dir."/".$finalfile5))
$name = basename($_FILES['pro_image_6']['name']);
$ext = substr(strrchr($name, "."), 1);
$randName = md5(rand() * time());
$finalfile6 = $randName . '.' . $ext;
$t_name = $_FILES['pro_image_6']['tmp_name'];
$dir = '../../images/properties/images/';
if(move_uploaded_file($t_name,$dir."/".$finalfile6))
$name = basename($_FILES['pro_image_7']['name']);
$ext = substr(strrchr($name, "."), 1);
$randName = md5(rand() * time());
$finalfile7 = $randName . '.' . $ext;
$t_name = $_FILES['pro_image_7']['tmp_name'];
$dir = '../../images/properties/images/';
if(move_uploaded_file($t_name,$dir."/".$finalfile7))
$name = basename($_FILES['pro_image_8']['name']);
$ext = substr(strrchr($name, "."), 1);
$randName = md5(rand() * time());
$finalfile8 = $randName . '.' . $ext;
$t_name = $_FILES['pro_image_8']['tmp_name'];
$dir = '../../images/properties/images/';
if(move_uploaded_file($t_name,$dir."/".$finalfile8))
$insertSQL = sprintf("INSERT INTO property_listings_db (property_listing_title, pro_image_1, pro_image_2, pro_image_3, pro_image_4, pro_image_5, pro_image_6, pro_image_7, pro_image_8, bathrooms, bedrooms, state_ID, city_ID, type_ID, property_listing_price, long_description, short_description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['property_listing_title'], "text"),
GetSQLValueString($finalfile1, "text"),
GetSQLValueString($finalfile2, "text"),
GetSQLValueString($finalfile3, "text"),
GetSQLValueString($finalfile4, "text"),
GetSQLValueString($finalfile5, "text"),
GetSQLValueString($finalfile6, "text"),
GetSQLValueString($finalfile7, "text"),
GetSQLValueString($finalfile8, "text"),
GetSQLValueString($_POST['bathrooms'], "text"),
GetSQLValueString($_POST['bedrooms'], "text"),
GetSQLValueString($_POST['state_ID'], "int"),
GetSQLValueString($_POST['city_ID'], "int"),
GetSQLValueString($_POST['type_ID'], "int"),
GetSQLValueString($_POST['property_listing_price'], "double"),
GetSQLValueString($_POST['long_description'], "text"),
GetSQLValueString($_POST['short_description'], "text"));
mysql_select_db($database_ireland_estate, $ireland_estate);
$Result1 = mysql_query($insertSQL, $ireland_estate) or die(mysql_error());
$insertGoTo = "add_new_listing_confirm.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
and this is the form
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="add_listing" id="add_listing">
<table width="600" border="0" align="center" cellpadding="10" cellspacing="0">
<tr>
<td width="136" align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Property Title:</td>
<td width="424"><span id="sprytextfield1">
<label for="property_listing_title"></label>
<input name="property_listing_title" type="text" id="property_listing_title" size="50" maxlength="100" />
<span class="textfieldRequiredMsg">*</span></span></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Primary Image:</td>
<td><label for="pro_image_1"></label>
<input name="pro_image_1" type="file" id="pro_image_1" size="50" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Image 1:</td>
<td><label for="pro_image_2"></label>
<input name="pro_image_2" type="file" id="pro_image_2" size="50" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Image 2:</td>
<td><label for="pro_image_3"></label>
<input name="pro_image_3" type="file" id="pro_image_3" size="50" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Image 3:</td>
<td><label for="pro_image_4"></label>
<input name="pro_image_4" type="file" id="pro_image_4" size="50" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Image 4:</td>
<td><label for="pro_image_5"></label>
<input name="pro_image_5" type="file" id="pro_image_5" size="50" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Image 5:</td>
<td><label for="pro_image_6"></label>
<input name="pro_image_6" type="file" id="pro_image_6" size="50" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Image 6:</td>
<td><label for="pro_image_7"></label>
<input name="pro_image_7" type="file" id="pro_image_7" size="50" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Image 7:</td>
<td><label for="pro_image_8"></label>
<input name="pro_image_8" type="file" id="pro_image_8" size="50" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>State:</td>
<td><span id="spryselect1">
<label for="state_ID"></label>
<select name="state_ID" id="state_ID">
<option value="">Select a State</option>
<?php
do {
?>
<option value="<?php echo $row_rs_States['state_ID']?>"><?php echo $row_rs_States['state_name']?></option>
<?php
} while ($row_rs_States = mysql_fetch_assoc($rs_States));
$rows = mysql_num_rows($rs_States);
if($rows > 0) {
mysql_data_seek($rs_States, 0);
$row_rs_States = mysql_fetch_assoc($rs_States);
}
?>
</select>
<span class="selectRequiredMsg">*</span></span></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>City:</td>
<td><span id="spryselect2">
<label for="city_ID"></label>
<select name="city_ID" id="city_ID">
<option value="">Select a City</option>
<?php
do {
?>
<option value="<?php echo $row_rs_city['city_ID']?>"><?php echo $row_rs_city['city_name']?></option>
<?php
} while ($row_rs_city = mysql_fetch_assoc($rs_city));
$rows = mysql_num_rows($rs_city);
if($rows > 0) {
mysql_data_seek($rs_city, 0);
$row_rs_city = mysql_fetch_assoc($rs_city);
}
?>
</select>
<span class="selectRequiredMsg">*</span></span></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Type:</td>
<td><span id="spryselect3">
<label for="type_ID"></label>
<select name="type_ID" id="type_ID">
<option value="">Select a Type</option>
<?php
do {
?>
<option value="<?php echo $row_rs_type['type_ID']?>"><?php echo $row_rs_type['type_name']?></option>
<?php
} while ($row_rs_type = mysql_fetch_assoc($rs_type));
$rows = mysql_num_rows($rs_type);
if($rows > 0) {
mysql_data_seek($rs_type, 0);
$row_rs_type = mysql_fetch_assoc($rs_type);
}
?>
</select>
<span class="selectRequiredMsg">*</span></span></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Price:</td>
<td><span id="sprytextfield2">
<label for="property_listing_price"></label>
<input type="text" name="property_listing_price" id="property_listing_price" />
<span class="textfieldRequiredMsg">*</span></span></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Number of Bedrooms:</td>
<td><span id="sprytextfield3">
<label for="bedrooms"></label>
<input type="text" name="bedrooms" id="bedrooms" />
<span class="textfieldRequiredMsg">*</span></span></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Number of Bathrooms:</td>
<td><span id="sprytextfield4">
<label for="bathrooms"></label>
<input type="text" name="bathrooms" id="bathrooms" />
<span class="textfieldRequiredMsg">*</span></span></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Long Description:</td>
<td><label for="long_description"></label>
<textarea name="long_description" id="long_description" cols="50" rows="10"></textarea></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="p_for_index"><span class="contact_form_text">*</span>Short Description:</td>
<td><label for="short_description"></label>
<textarea name="short_description" id="short_description" cols="50" rows="5"></textarea></td>
</tr>
<tr>
<td align="right" nowrap="nowrap"> </td>
<td><input type="submit" name="insert" id="insert" value="Add Listing" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="add_listing" />
</form>
Thank you for reading through it all, any help is appreciated,