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.

Link to comment
Share on other sites

$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.
 

Link to comment
Share on other sites

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>';
}

Edited by aysiu
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.