Page 1 of 1

Problem with page that contains form and DB list

Posted: Mon Mar 16, 2009 8:19 pm
by kendopt
Hi.
I'm doing a form with a listing of database field on the same page.
It's a family listing page where there's a form to add new families.when i submit the form the list doesn't reload. what can i do?

List the families:

Code: Select all

<?php
    include 'l3con.php';
    
    
    $consulta_familias = mysql_query("SELECT * FROM familias", $ligacao);
    
    
   
        $cor="1";
 
        echo '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="2">';
        echo "<tr bgcolor='#419aee'>
                <td>Familia</td>
                <td>Imagem</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>";
                
        while($linhas=mysql_fetch_array($consulta_familias))
        
        
        
        {
            $id = $linhas['id'];
        
            if($cor==1)
                {
                    echo "<tr bgcolor='#c3e1fb'>
                    <td>".$linhas['familia']."</td><td>".$linhas['imagem']."</td><td align='center'><a href='editar_receita.php?id_new=$id'>editar</a></td><td align='center'><a href='apagar_receita.php?id_new=$id'>apagar</a></td>
                    </tr>";
                    $cor="2";
                }
 
                else 
                {
                    echo "<tr bgcolor='#fcedcd'>
                    <td>".$linhas['familia']."</td><td>".$linhas['imagem']."</td><td align='center'><a href='editar_receita.php?id_new=$id'>editar</a></td><td align='center'><a href='apagar_receita.php?id_new=$id'>apagar</a></td>
                    </tr>";
                    $cor="1";
                }
 
        }
        echo '</table>';
 ?>   
    
 
Now the Form part:

Code: Select all

 
<?php
<form enctype="multipart/form-data" action="familias.php" method="POST">
              <table width="100%" border="0" cellspacing="0" cellpadding="5">
                <tr>
                  <td width="74">Familia:</td>
                  <td colspan="2"><input type="text" name="familia" id="familia" /></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td colspan="2">
Choose an image: </td>
                </tr>
                <tr>
                  <td>Imagem:</td>
                  <td colspan="2"><input name="uploaded" type="file" /></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td width="131"><input type="submit" value="Guardar" /></td>                              
                  <td width="69"><div align="center"><a href="#" onclick="setVisibility('formulario', 'none');">Esconder</a></div></td>
                </table>
               </form>
          <?php
            $familia = $_POST['familia'];
            $imagem = $_POST['uploaded'];
            
            if(isset($familia))
            {
                    $target = "images/";
                    $target = $target . basename( $_FILES['uploaded']['name']) ;
                    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
                        {
                            
                            $data = "INSERT INTO `ods`.`familias` 
                                        (`id` , `familia`,`imagem` )
                                    VALUES 
                                    (NULL , '$familia', '$imagem');";
    
                            mysql_query($data);
                            unset($familia,$imagem,$_POST['familia'],$_POST['imagem']);
                            
                            echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
                        
                        }
                    else 
                        {
                            echo "There has been a problem uploading.";
                        }
                        
                
            }
                
?>
Everything works fine except when i submit the list won't update.
I think its some kind of cache problem. Because when i open the page again it shows everything right.
Once the form sends you to to the same page it should reload/refresh contents right?
Or is it something about the insert in mysql that takes more time than the page to refresh?