Variable does not work in script

Asked

Viewed 39 times

1

Gentlemen, I’m new here, and I’m unanswered as to what’s going on. I created a $rga variable to insert through a field, but it doesn’t work.

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

If I put the lines

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

below the }
Then the problem becomes uploads/$filename who doesn’t carry the photo. And the variable $rga starts to work.

Could someone 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>
  • Thanks friends for the tip.. already rosolvido.

1 answer

0

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

Watch out for the if($_POST['submit']){...} That one 'submit' that you put, comes from your input name='submit'. When you merge your forms, you need to keep that input with that name if you want that if to work.

  • Could modify by posting the example ?

  • Already WORKED, THANKS. If you want to see how it works, go to www,rganimal.com.br

Browser other questions tagged

You are not signed in. Login or sign up in order to post.