Jump to content

[SOLVED] while loop inside if (!empty($_FILES['file']['tmp_name']))


scarhand

Recommended Posts

why isnt this working? when i press the submit button it tries to go to the new page but it seems like it just keeps loading something over and over and over

 

the $myid variable is an integer like 23, or whatever.

 

<?php
if (!empty($_FILES['file']['tmp_name']))
    {
      while ($row = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id='$myid'")))
      {
        $oldphoto = $row['myphoto'];
        echo $oldphoto;
      }
}
?>

Because you are lazy. In your while loop the query is being re-run over and over...

Should be:

 

<?php
if (!empty($_FILES['file']['tmp_name']))
    {
      $result = mysql_query("SELECT * FROM users WHERE id='$myid'");
      while ($row = mysql_fetch_array($result))
      {
        $oldphoto = $row['myphoto'];
        echo $oldphoto;
      }
}
?>

 

Orio.

add error reporting to the query

<?php
<?php
if (!empty($_FILES['file']['tmp_name']))
    {
      $q = "Select * from `users` where id = '".$myid."'";
      $result = mysql_query($q) or die(mysql_error()."<br />".$q);
     if(mysql_num_rows($result) >0){
      while ($row = mysql_fetch_array($result))
      {
        $oldphoto = $row['myphoto'];
        echo $oldphoto;
      }
      }
    else{
        echo "No Records found.";
    }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.