-2

I'm having an issue with my php script. Very new to php so I know it's not the best. The following errors occur when submitting my form.

Notice: Undefined index: username in C:\xampp\htdocs\AppX1\signin.php on line 6 Notice: Undefined index: password in C:\xampp\htdocs\AppX1\signin.php on line 7 Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in C:\xampp\htdocs\AppX1\signin.php:13 Stack trace: #0 {main} thrown in C:\xampp\htdocs\AppX1\signin.php on line 13

I've read a few posts saying to use a isset method although I'm not sure where to put this or if it applies to my situation.

<form action="signin.php" id="signInForm">
    <fieldset>
        <label class="fieldLabel" for="uname">Email Address</label>
        <input class="fieldInput" type="text" id="uname" name="username">
        <label class="fieldLabel" for="pword">Password</label>
        <input class="fieldInput" type="password" id="pword" name="password">
        <input class="submitBtn" type="submit" value="Submit">
    </fieldset>
</form>

<?php

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


  // sql injection prevention
  $username = stripcslashes($username);
  $password = stripcslashes($password);
  $username = mysql_real_escape_string($username);
  $password = mysql_real_escape_string($password);

  //connect to server and select SQLiteDatabase
  mysql_connect("localhost", "root", "");
  mysql_select_db("user");

  //query db for user
  $result = mysql_query("SELECT * FROM user where email = '$username' and password = '$password'")
            or die("Failed to query database ".mysql_error());

  $row = mysql_fetch_array($result);
  if ($row['email'] == $username && $row['password'] == $password) {
    echo "Login Success!".$row['email'];
  }
  else {
    echo "Login Failed";
  }



?>

halfer
  • 19,824
  • 17
  • 99
  • 186
AbuN2286
  • 153
  • 16

2 Answers2

0

<form action="signin.php" id="signInForm">

You are missing your method for form. <form action="signin.php" id="signInForm" method="post" >

Can Oezlemis
  • 169
  • 1
  • 10
0

Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in C:\xampp\htdocs\AppX1\signin.php:13

If you use PHP 7, mysql_real_escape_string function is removed. Try to use mysqli_real_escape_string instead and make sure you have loaded mysqli PHP module in php.ini (use phpinfo() or php -I | grep -i mysqli from command line to check if the module has been loaded)

Anggara
  • 625
  • 4
  • 8