Karate_Dog
Karate_Dog

Reputation: 1277

Form cannot pass value in php

I want to pass the $username value to doMember.php page from member.php with form :

member :

$username = $_GET['user'];
<form name="member" method="get" action="doMember.php?user=<?php echo $username;?>">

in the doMember.php page :

$username = $_GET["user"];
echo $username;

but the $username in doMember.php is empty. Is there something missing?

Upvotes: 0

Views: 176

Answers (5)

Henrik Karlsson
Henrik Karlsson

Reputation: 5733

You should place the username in an

<input type="hidden" name ="username" val="usr">

instead

Upvotes: 2

verisimilitude
verisimilitude

Reputation: 5108

Can't you include the value of $user_name in a hidden variable in your so $username = $_GET['user'];

    <form name="member" method="get" action="doMember.php">
      <input type="hidden" id="user_name" name="user_name" value="<?php echo $username; ?>"
      .
      .
      . 
    </form>
  

Upvotes: 1

leechyeah
leechyeah

Reputation: 91

Form method='post'

The field name of that form must be named "user"

Upvotes: 1

CodeCaster
CodeCaster

Reputation: 151720

You should not set the parameters in the action. Take a look at the generated HTML, you'll see your form will be sent to "doMember.php?user=", so you'll always send an empty user.

The browser will append all form variables to the action upon submit, so simply put doMember.php.

Upvotes: 2

Ron van der Heijden
Ron van der Heijden

Reputation: 15080

HTML and PHP are not the same

$username = $_GET['user'];
echo '<form name="member" method="get" action="doMember.php?user='.$username.'">';

Upvotes: 3

Related Questions