error message displaying when field isn't empty

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James
    New Member
    • Jun 2011
    • 17

    error message displaying when field isn't empty

    Hi. For some reason when I choose to update details in a database, a field which displays the image name stored in a database is deemed to be empty when it isn't empty. Any feedback would be much appreciated.

    Code:
    <?php 
    				
    				if ($error == true)
    					{
    						echo '<div style="padding:5px 10px 5px 10px; margin-top:20px;  border:2px solid #FF0000; color:#FF0000; width:345px;">'.$error.'</div>';
    					}
    					
    			?> 	
    			
    			<form id="edit-form" action="" method="post" enctype="multipart/form-data">
    				<input type="hidden" name="id" value="<?php echo $id; ?>" />
    
    <table>
    <tr>
    							<td><strong>Photo <span class="red">*</span></strong></td>
    							<td><input type="hidden" name="size" value="350000" /><input type="text" value="<?php echo $photo; ?>" /><input type="file" name="photo" value="<?php echo $photo; ?>" /></td>
    </tr>
    Code:
    <?php
    
    	include('connect.php');
    
    	if (isset($_POST['submit']))
    		{ 
    				
    			if (is_numeric($_POST['id']))
    			{
    				$id = $_POST['id'];
    				$price = mysql_real_escape_string(htmlspecialchars($_POST['price']));
    				$rooms = mysql_real_escape_string(htmlspecialchars($_POST['rooms']));
    				$address = mysql_real_escape_string(htmlspecialchars($_POST['address']));
    				$description = mysql_real_escape_string(htmlspecialchars($_POST['description']));
    				$photo = (mysql_real_escape_string($_FILES['photo']['name']));
    
    		 
    					if ($price == '' ||  $rooms == '' || $address == '' || $description == '' || $photo =='')
    					{
    
    						$error = 'ERROR TRYING TO UPDATE RECORD: Please fill in all required fields';
    
    						form($id, $price, $rooms, $address, $description, $photo, $error);
    
    					}
    					
    					else
    					{
    						$folder = "./houses/";
    						move_uploaded_file($_FILES["photo"]["tmp_name"] , "$folder".$_FILES["photo"]["name"]);
    							
    						mysql_query("UPDATE house_info SET price='$price', rooms='$rooms', address='$address', description='$description', photo='$photo' WHERE id='$id'")
    						or die(mysql_error()); 
    
    						header("Location:admin.php");
    
    					}
Working...