Variable does not work in script

1

Srs, I'm new here, I have no answer to know what is happening. I created a $ rga variable to insert through a field, but it does not work.

This srcipt uploads a photo and resizes it. In the displayed mode it does not accept the variable $ rga

If I put the lines

$rga = $_POST['rga'];
mysql_query("  UPDATE penpals SET picture = ' uploads/$filename ' WHERE ID = '$rga' ");

below }
Then the problem happens to be uploads/$filename that does not load the photo. And the $rga variable starts to work.

Can anyone help me?

<?
if ( isset( $_POST['submit'] ) ){   
   $pasta = 'uploads';
   $file = $_FILES['arquivo'];
   $temp = $file['tmp_name'];
   $filename = $file['name'];
    $largura_max    = 130;
   $altura_max  = 130;
   require ('redimensiona_fotos.php');
   $result = upload($temp, $filename, $largura_max, $altura_max, $pasta);
echo    "<img src=\"uploads/$filename\">"; 

$rga = $_POST['rga'];
mysql_query("  UPDATE penpals SET picture = ' uploads/$filename ' WHERE ID = '$rga' ");
}
?>

<form action="" method="post" enctype="multipart/form-data">
   <label for="arquivo">Arquivo:</label>
   <input type="file" name="arquivo" id="arquivo" /> 
   <br />
   <input type="submit" name="submit" value="Abrir imagem" />
</form>

<form action="" method="post" enctype="multipart/form-data">
<span class="add-on">User</span>
<input id="rga" name="rga" type="text" maxlength="40" placeholder="Informe ID" />
<input class="form_botao" type="submit" name="Enviar" value="Precione para Enviar a FOTO - SALVE ABAIXO "><br>
</form>
    
asked by anonymous 20.01.2017 / 17:31

1 answer

0

You have two forms ( <form> ). By clicking on the submit button of one, only the data of it is submitted. If your idea is for the user to submit one form first and then another, then you need to make a php code to handle each form call separately. Otherwise, if your idea is for the user to submit only one form, you need to delete one, and take your fields to the other form, so that only one form with all the fields is left.

Watch out for if($_POST['submit']){...} This 'submit' you've placed comes from your input name='submit' . When you merge your forms, you need to keep this input with this name if you want this if to work.

    
20.01.2017 / 17:56