OK, any and all help very much appreciated, 'cos this is driving me nuts! This section of code isnt working - i.e. nothing is being added to my database on completion of all fields and clicking the submit button. By process of elimination, I can confirm that all external files referenced are functioning correctly, because all other pages of code within this package do what they are supposed to!
I have tried absolutely every little tweak I can think of, and still this code does nothing - it even returns the success message to say the process has worked, but it hasn't. My error logs show nothing, and the SQL statement appears to be correct. Any ideas - Am I missing something glaringly obvious?
<?php
require ( "config.php" );
if (isset($_COOKIE["ValidUserAdmin"]))
{
require ( "../CGI.php" );
require ( "../SQL.php" );
require ( "resizer.php" );
$cgi = new CGI ();
$sql = new SQL ( $DBusername, $DBpassword, $server, $database );
if ( ! $sql->isConnected () )
{
die ( $DatabaseError );
}
?><HTML>
<HEAD>
<head stuff>
</HEAD>
<BODY>
<TABLE WIDTH="100%">
<TBODY>
<TR>
<TD BGCOLOR="#333333"> <?PHP include "header.php"; ?>
<TABLE WIDTH="100%">
<TBODY>
<TR>
<TD COLSPAN="4">
<TABLE WIDTH="100%">
<TR>
<TD ALIGN="LEFT" VALIGN="TOP"> <?PHP include "leftmenu.php"; ?></TD>
<TD VALIGN="TOP" WIDTH="100%">
<H2 ALIGN="LEFT"><IMG SRC="images/spacer.gif" HEIGHT="10" WIDTH="15">Add New Property</H2>
<p></p>
<?php
if ( $cgi->getValue ( "op" ) == "AddProperty" )
{
for ( $i = 0; $i < 4; ++$i )
{
$propertyphotos [ $i ] = "";
$t = "propertyphoto" . ( $i + 1 );
error_log ( "Checking propertyphoto" . ( $i + 1 ) );
if ( ! isset ( $_FILES [ $t ] ) ||
! is_uploaded_file ( $_FILES [ $t ] [ 'tmp_name' ] ) )
{
error_log ( "Breaking, no uploaded file?" );
continue;
}
error_log ( "\$_FILES [ " . $t . " ] [ \"error\" ] = " . $_FILES [ $t ] [ "error" ] . " (UPLOAD_ERR_OK = " . UPLOAD_ERR_OK . ")" );
if ( $_FILES [ $t ] [ "error" ] == UPLOAD_ERR_OK )
{
$tmp_name = $_FILES [ $t ] [ "tmp_name" ];
$name = $_FILES [ $t ] [ "name" ];
$propertyphotos [ $i ] = $cgi->getValue ( "propertyref" ) . "-" . $name;
resizeImage (
$tmp_name, IMG_JPEG,
$ImagePath . "/" . $propertyphotos [ $i ],
$defaultImageWidth, $defaultImageHeight, IMG_JPEG );
//move_uploaded_file (
// $tmp_name, $ImagePath . "/" . $propertyphotos [ $i ] );
//error_log ( "Upload seems OK, trying to copy from " . $tmp_name . " to " . $ImagePath . "/" . $propertyphotos [ $i ] );
}
}
$sql->execute ( "INSERT INTO " . $property_table . "
(
id,
propertyref,
propertytype,
propertyprice,
propertybedrooms,
propertyaddress,
propertylocation,
shortdescription,
longdescription,
propertystatus,
propertyphoto1,
propertyphoto2,
propertyphoto3,
propertyphoto4,
propertyviews,
propertyshow,
dateadded
)
VALUES
(
NULL,
" . $sql->quote ( $cgi->getValue ( "propertyref" ) ) . ",
" . $sql->quote ( $cgi->getValue ( "propertytype" ) ) . ",
" . $sql->quote ( $cgi->getValue ( "propertyprice" ) ) . ",
" . $sql->quote ( $cgi->getValue ( "propertybedrooms" ) ) . ",
" . $sql->quote ( $cgi->getValue ( "propertyaddress" ) ) . ",
" . $sql->quote ( $cgi->getValue ( "propertylocation" ) ) . ",
" . $sql->quote ( $cgi->getValue ( "shortdescription" ) ) . ",
" . $sql->quote ( $cgi->getValue ( "longdescription" ) ) . ",
" . $sql->quote ( $cgi->getValue ( "propertystatus" ) ) . ",
" . $sql->quote ( $propertyphotos [ 0 ] ) . ",
" . $sql->quote ( $propertyphotos [ 1 ] ) . ",
" . $sql->quote ( $propertyphotos [ 2 ] ) . ",
" . $sql->quote ( $propertyphotos [ 3 ] ) . ",
0,
" . ( strtolower ( $cgi->getValue ( "propertyshow" ) ) == "yes" ?
1 : 0 ) . ",
$todaydate
)" );
?>
<br>
<br>
<br>
<p align="center"><b>The New Property (<b>
<?php
echo $cgi->getValue ( "propertyref" ); ?>
</b>) has been added successfully.</b></p>
<br>
<?php
}
else
{
?>
<TABLE WIDTH="95%">
<TR>
<TD>
<p>Fill in all the details below to add a new property to the database. As soon as the property has been added, it will be available on your website for your visitors to search.</p>
</TD>
</TR>
</TABLE><br>
<form method="post" enctype="multipart/form-data">
<input name="op" type="hidden" value="AddProperty">
<br>
<table width="95%">
<tr>
<td width="165">
<p align="right">Property Ref Number:</p></td>
<td>
<p>
<input type="TEXT" name="propertyref" size="20" maxlength="50">
</p></td>
</tr>
<tr>
<td width="165">
<p align="right">Select Property Type:</p></td>
<td><p>
<select name="propertytype" size="1">
<?PHP
$rows = $sql->execute (
"SELECT * FROM " . $propertytypes_table .
" ORDER BY propertytype ASC", SQL_RETURN_ASSOC );
for ( $i = 0; $i < sizeof ( $rows ); ++$i )
{
$row = $rows [ $i ];
?>
<option value="<?php echo $cgi->htmlEncode ( $row [ "id" ] ); ?>">
<?php
echo $cgi->htmlEncode ( $row [ "propertytype" ] ); ?>
</option>
<?php
}
?>
</select> <i class="row1">(<a href="property_type_add.php">Add new property type</a>)</i>
</p></td>
</tr>
<tr>
<td width="165">
<p align="right">Enter Property Price:</p></td>
<td bgcolor="#FFFFFF">
<p> <?php echo $CurrencyUnit; ?>
<input type="TEXT" name="propertyprice" size="10"
maxlength="20" class="textinput">
</p></td>
</tr>
<tr>
<td width="165">
<p align="right">Number of Bedrooms:</p></td>
<td>
<p>
<select name="propertybedrooms">
<option value="" selected="SELECTED">Please Select</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
</p></td>
</tr>
<tr>
<td width="165">
<p align="right">Address of Property:</p></td>
<td>
<p>
<input type="TEXT" name="propertyaddress" size="50"
maxlength="100">
</p></td>
</tr>
<tr>
<td width="165">
<p align="right">Location of Property:</p></td>
<td><p>
<select name="propertylocation" size="1">
<?PHP
$rows = $sql->execute ( "SELECT * FROM " .
$propertylocations_table . " ORDER BY propertylocation ASC",
SQL_RETURN_ASSOC );
for ( $i = 0; $i < sizeof ( $rows ); ++$i )
{
$row = $rows [ $i ];
?>
<option value="<?php echo $cgi->htmlEncode ( $row [ "id" ] ); ?>">
<?php
echo $cgi->htmlEncode ( $row [ "propertylocation" ] ); ?>
</option>
<?php
}
?>
</select> <i class="row1">(<a href="property_location_add.php">Add new locations</a>)</i>
</p></td>
</tr>
<tr>
<td width="165" valign="TOP">
<p align="right">Short Property Description:</p></td>
<td>
<p>
<textarea name="shortdescription" rows="4" cols="45"></textarea>
</p></td>
</tr>
<tr>
<td width="165" valign="TOP">
<p align="right">Long Property Description:</p></td>
<td>
<p>
<textarea name="longdescription" rows="15" cols="45"></textarea>
</p></td>
</tr>
<tr>
<td width="165">
<p align="right">Status:</p></td>
<td>
<p>
<select name="propertystatus">
<?php
$rows = $sql->execute ( "SELECT * FROM " .
$propertystatus_table . " ORDER BY propertystatus ASC",
SQL_RETURN_ASSOC );
for ( $i = 0; $i < sizeof ( $rows ); ++$i )
{
$row = $rows [ $i ];
?>
<option value="<?php echo $cgi->htmlEncode ( $row [ "id" ] ); ?>">
<?php
echo $cgi->htmlEncode ( $row [ "propertystatus" ] ); ?>
</option>
<?php
}
?>
</select>
<i class="row1">(Select the Property Status)</i></p></td>
</tr>
<tr>
<td width="165">
<p align="right">Listing Option:</p></td>
<td>
<p>
<select name="propertyshow">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</p></td>
</tr>
<tr>
<td width="165">
<p align="right"></p></td>
<td>
<p> </p></td>
</tr>
<tr>
<td width="165" valign="TOP">
<p align="right">Upload Property Photos:<br>
<i>(If no photo available leave blank for default image)</i></p></td>
<td><p> Picture 1:
<input name="propertyphoto1" type="file" size="35" />
</td></tr><tr><td>.</td>
<td><p> Picture 2:
<input name="propertyphoto2" type="file" size="35" />
</td></tr><tr><td>.</td>
<td><p> Picture 3:
<input name="propertyphoto3" type="file" size="35" />
</td></tr><tr><td>.</td>
<td><p> Picture 4:
<input name="propertyphoto4" type="file" size="35" />
</td>
</tr>
</table><br>
<p align="center">
<input value="Click Here to Add New Property" type="submit" ONCLICK="return confirm('Are you sure you want to Add this New Property Listing?');">
</p>
<?php
}
?>
<br>
<br>
</form></TD>
</TR>
</TABLE> </TD>
</TR>
</TBODY>
</TABLE> </TD>
</TR>
</TBODY>
</TABLE> <?PHP include "footer.php"; ?>
</BODY>
</HTML>
<?php
}
else
{
header("Location: index.php");
exit;
}
?>
Oh, and minor niggle, but the image uploader doesnt work either - this is the next item on my list of things to do, but the sql section is definitely the priority, as without the ability to add into the database, this code is pretty much useless!
I am eternally grateful to anybody who can save the last few strands of my hair from being clawed out in my frustration!