Jump to content
Sign in to follow this  
Bird

$_POST not passing variables

Recommended Posts

Hello!

I know there are a lot of posts on the internet about this but I can't find one that solves my problem.

I'm following the PHP Login Page tutorial on w3schools.com and am having some trouble.

https://www.w3schools.com/howto/howto_css_login_form.asp

 

It is not passing the 'uname' and 'psw' to action_page.php. Not sure why... Everything looks referenced correctly

 

I have 2 scripts here:

1) index.html(This seems to be working as-far as sending the credentials to action_page.php, I see the URL at the top is to action_page.php and includes the input username and password)

<body>
<form action="/action_page.php">
  <div class="imgcontainer">
    <img src="kje_logo.png" alt="Avatar" class="avatar">
  </div>

  <div class="container">
    <label for="uname"><b>Username</b></label>
    <input type="text" placeholder="Enter Username" name="uname" required>

    <label for="psw"><b>Password</b></label>
    <input type="password" placeholder="Enter Password" name="psw" required>

    <button type="submit">Login</button>
  </div>
</form>
</body>

2*) action_page

<?php
$dbservername = "localhost";
$dbusername = "****";
$dbpassword = "****";
$dbname = "****";
$username = $_POST['uname'];
$password = $_POST['psw'];

// Create connection
$conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else{
	echo 'Connected! ';
$sql = "SELECT * FROM KJE WHERE username = '$username' AND password = '$password' ";//when i change $username and $password to the correct credentials, it says "Login Success"
$result = mysqli_query($conn,$sql);
$check = mysqli_fetch_array($result);
if(isset($check)){
echo 'Login Success.';
}else{
echo 'Login Failure!';
}
}
?>

 

 

Edited by Bird

Share this post


Link to post
Share on other sites

Your for needs a method="POST" attribute.

  • Thanks 1

Share this post


Link to post
Share on other sites

 

Got it working! Not sure what I did differently from earlier(I took post out while troubleshooting)... Probably just being a dumby. Thanks a ton

 

Edited by Bird

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...