Jump to content

Recommended Posts

<?php
require 'config.php';
if (isset($_POST['login'])) {

  $password = mysqli_real_escape_string($con, $_POST['tpw']);
  $username=  mysqli_real_escape_string($con, $_POST['username']);
   
  
      $query = "SELECT * FROM tinfo WHERE username='$username' AND password='$password'";
      $results = mysqli_query($con, $query);
      if (mysqli_num_rows($results) == 1) {
        $_SESSION['username'] = $username;
          $_SESSION['success'] = "You are now logged in";
        header('location: ../html/register.html');
      }else {
          echo "Wrong username/password combination";
      }
  
  
}
?>

Link to comment
https://forums.phpfreaks.com/topic/311625-index-undefined/
Share on other sites

Which "index" does the error message refer to? What is the error message?

Side note: if you're not doing so already, you'll want to look into password security. More information can be found here:
https://www.php.net/manual/en/faq.passwords.php

Edited by cyberRobot
  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/311625-index-undefined/#findComment-1581998
Share on other sites

<form method="post" action="../php/tlogin.php" name="form" onsubmit="return validated()" ><br></br>

<lable> Username</lable>
<input type="text"  placeholder="Enter Username" name="username" id="uname" required>
<div id="uname_error">Please Fill Up your Username</div>
 <br></br>

<lable>Password</lable>  
<input type="password" placeholder="Enter Password" name="tpw" id="tpw" required><br></br>
<div id="pass_error">Please Fill Up your Password</div>
<br></br>


<button type="Submit" name="login">Login</button><br></br>

<a href="#">Lost Your Password?</a><br>
<a href="#">Don't have an account?</a>
</form>

Link to comment
https://forums.phpfreaks.com/topic/311625-index-undefined/#findComment-1582001
Share on other sites

Try adding the following echo statement inside your if construct to see what $_POST contains:

if (isset($_POST['login'])) {

    echo '<pre>' . print_r($_POST, true) . '</pre>';

After adding the line, try submitting the form, but don't use a real login. Just enter random characters. What does the output look like? Note that you're looking for output like the following (please don't post real usernames/passwords):

Array
(
    [tpw] => sdflaje
	...
)

 

Link to comment
https://forums.phpfreaks.com/topic/311625-index-undefined/#findComment-1582002
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.