Jump to content

Having Trouble Passing Values From HTML page to PHP page


2l8vsan

Recommended Posts

I have two pages. A login.html and a check.php page to check the credentials of somebody logging in to my site.

 

My HTML (omitted body etc):

<form action = "check.php" METHOD = "post" >
   <label>username<input type = "text" name = "username" size = "25" maxlength = "30" /></label><br />
    <label>password<input type = "password" name = "password" size = "25" maxlength = "30" /></label><br />
    <input type = "submit" class = "button" value = "Submit" />

check.php page

    <?php

session_start();

$user = $_POST['username'];
$pass = $_POST['password'];

echo $user;

?>
    <p>Hello <?php echo $user; ?></p>
    <p>Goodbye <?php echo ("$password"); ?></p>
    

    <label><a href = "Login.html" name = "login">Go back there</a></label>

   
   </body>
   </html>

I have apache running under XAMPP.

I can't even see the values pass over. It just shows the HTML. Am I doing something wrong? I had it working earlier.

Above is just echo statements attempting to get some value passed over. But I get nothing.

$user = $_POST['username'];
$pass = $_POST['password'];

echo $user;

?>
    <p>Hello <?php echo $user; ?></p>
    <p>Goodbye <?php echo ("$password"); ?></p>

 

As you can see from the highlighting, you store in $pass then echo $password. However, $user should echo.

Also, there should be no whitespace before the opening <?php tag otherwise session_start() will fail.
 

Are you sure the POST data is even being set? Before this bit

$user = $_POST['username'];
$pass = $_POST['password'];

echo $user;

Try putting in this

if(isset($_POST['username'])){
echo '<p>There is a username set, and it is ' . $_POST['username'] . '</p>';
} else {
echo '<p>There is no username set.</p>';
}

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.