By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,066 Members | 1,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,066 IT Pros & Developers. It's quick & easy.

error message displaying when field isn't empty

P: 17
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php 
  3.  
  4.                 if ($error == true)
  5.                     {
  6.                         echo '<div style="padding:5px 10px 5px 10px; margin-top:20px;  border:2px solid #FF0000; color:#FF0000; width:345px;">'.$error.'</div>';
  7.                     }
  8.  
  9.             ?>     
  10.  
  11.             <form id="edit-form" action="" method="post" enctype="multipart/form-data">
  12.                 <input type="hidden" name="id" value="<?php echo $id; ?>" />
  13.  
  14. <table>
  15. <tr>
  16.                             <td><strong>Photo <span class="red">*</span></strong></td>
  17.                             <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>
  18. </tr>
  19.  
  20.  
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     include('connect.php');
  4.  
  5.     if (isset($_POST['submit']))
  6.         { 
  7.  
  8.             if (is_numeric($_POST['id']))
  9.             {
  10.                 $id = $_POST['id'];
  11.                 $price = mysql_real_escape_string(htmlspecialchars($_POST['price']));
  12.                 $rooms = mysql_real_escape_string(htmlspecialchars($_POST['rooms']));
  13.                 $address = mysql_real_escape_string(htmlspecialchars($_POST['address']));
  14.                 $description = mysql_real_escape_string(htmlspecialchars($_POST['description']));
  15.                 $photo = (mysql_real_escape_string($_FILES['photo']['name']));
  16.  
  17.  
  18.                     if ($price == '' ||  $rooms == '' || $address == '' || $description == '' || $photo =='')
  19.                     {
  20.  
  21.                         $error = 'ERROR TRYING TO UPDATE RECORD: Please fill in all required fields';
  22.  
  23.                         form($id, $price, $rooms, $address, $description, $photo, $error);
  24.  
  25.                     }
  26.  
  27.                     else
  28.                     {
  29.                         $folder = "./houses/";
  30.                         move_uploaded_file($_FILES["photo"]["tmp_name"] , "$folder".$_FILES["photo"]["name"]);
  31.  
  32.                         mysql_query("UPDATE house_info SET price='$price', rooms='$rooms', address='$address', description='$description', photo='$photo' WHERE id='$id'")
  33.                         or die(mysql_error()); 
  34.  
  35.                         header("Location:admin.php");
  36.  
  37.                     }
  38.  
Dec 21 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.