php - showing invalid message before uploading any image -


showing invalid error message on screen before uploading image on screen index.php

    <html><body>         <form action="index.php" method="post" enctype="multipart/form-data">     <table  align="center" cellspacing="0" cellpadding="6"  bgcolor="#cccccc" border="1" bordercolor="#000000">     <tr>     <td >firstname:</td><td><input type="text"  name="fname" /></td></tr><br/><br/><br/>     <tr>     <td >regsternumber:</td><td><input type="text" name="regno"/></td></tr><br/>     <tr>     <td>uploadphoto:</td><td><input type="file" name="image" /></td></tr>     </table>      <br><br><br>     <center>           <input  type="submit" /></center>     </form>     </form>     <form action ="table.php" method="post">     search :<select   name="search">     <option>please select     </option>     <?php     mysql_connect("localhost","root","")or die(mysql_error());     mysql_select_db("databaseimage") or die(mysql_error());     $query ="select reg store";     $result=mysql_query($query);     while($nt=mysql_fetch_array($result)){     echo "<option value=".$nt['reg'].">".$nt['reg']."</option>";     }      ?>      </select>     <input type="submit" name="submit">     </form>     <?php      //connect database     mysql_connect("localhost","root","")or die(mysql_error());     mysql_select_db("databaseimage") or die(mysql_error());       $name=$_post['fname'];      $regno=$_post['regno'];        //file properties          $file   =$_files['image']['tmp_name'];         if(!isset($file))             {                  echo "please select image";              }         else             {                  $image              =addslashes(file_get_contents ($_files['image']['tmp_name']   ) );                  $image_name    =addslashes($_files['image']['name']);                 $image_size         =getimagesize($_files['image']['tmp_name']);             }          if($image_size==false)            {                     echo "not valid image";                     }                      else                     {                     $order = "insert store(name,image,fname,reg)values('$image_name','$image','$name','$regno')";      if (!mysql_query($order)) { // error handling          echo "<script>alert('duplicate data entered');</script>";      }                     }     ?>        </body>     </html> 

showing invalid error message on screen before uploading image "not valid image" please me how rectify error message.

you need first check if form submitted verifying $_post exists.

verify isset() and/or is_array() here, , attempt process upload if form has been submitted (thus $_post variable populated posted data).

[...] <?php   if ( isset( $_post ) && is_array( $_post ) ) {  //connect database mysql_connect("localhost","root","")or die(mysql_error()); mysql_select_db("databaseimage") or die(mysql_error());   $name=$_post['fname'];  $regno=$_post['regno'];    //file properties      $file   =$_files['image']['tmp_name'];     if(!isset($file))         {              echo "please select image";          }     else         {              $image              =addslashes(file_get_contents ($_files['image']['tmp_name']   ) );              $image_name    =addslashes($_files['image']['name']);             $image_size         =getimagesize($_files['image']['tmp_name']);         }      if($image_size==false)        {                 echo "not valid image";                 }                  else                 {                 $order = "insert store(name,image,fname,reg)values('$image_name','$image','$name','$regno')";  if (!mysql_query($order)) { // error handling      echo "<script>alert('duplicate data entered');</script>";  }                 } } // closing if(..) ?> [...] 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -