warrens0017 Posted January 3, 2017 Share Posted January 3, 2017 Hi everyone. So I am have an issue to were I am trying to send information to my database and I get this error: NOTICE: Undefined index This is the code I am using: index.php <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Test Page</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <form action="signup.php" methos="POST"> <input type="text" name="first" placeholder="First Name"><br> <input type="text" name="last" placeholder="Last Name"><br> <input type="text" name="uid" placeholder="Username"><br> <input type="password" name="pwd" placeholder="Password"><br> <button type="submit">SIGN UP</button> </form> </body> </html> signup.php <?php include 'dbh.php'; $first = $_POST['first']; $last = $_POST['last']; $uid = $_POST['uid']; $pwd = $_POST['pwd']; $sql = "INSERT INTO username (first, last, uid, pwd) VALUES ('$first', '$last', '$uid', '$pwd')"; $result = mysqli_query($conn, $sql); ?> dbh.php <?php $conn = mysqli_connect("localhost", "root", "", "logintest"); if (!$conn) { die("Connection failed: ".mysqli_connect_error()); } ?> So this is the code I am using. I know it is connecting to the database because the PRIMARY KEY is entering without an issue but the information is now being filled in. I.E. First name, Last name, User, and Password. If anyone can help me that would be great. Link to comment Share on other sites More sharing options...
dsonesuk Posted January 3, 2017 Share Posted January 3, 2017 'is now' ??? 'is not' no index means you are referring to name not within $_POST array, which is probably because of <form action="signup.php" methos="POST"> instead of <form action="signup.php" method="post"> if primary key is auto increment it will add value if the other fields accept null. 1 Link to comment Share on other sites More sharing options...
warrens0017 Posted January 3, 2017 Author Share Posted January 3, 2017 Thank you very much. I read over the code like ten times and didn't notice that. Link to comment Share on other sites More sharing options...
warrens0017 Posted January 3, 2017 Author Share Posted January 3, 2017 Okay one more thing and I should be good. I got all that fixed and worked out, but now I am trying to create a login and I am getting this error: Warning: mysqli_fetch_assoc() expects parameter 1 to be resource, boolean given in Here is the code that I am working with: login.php <?php include 'dbh.php'; $uid = $_POST['uid']; $pwd = $_POST['pwd']; $sql = "SELECT * FROM username WHERE uid='$uid' AND pwd'$pwd'"; $result = mysqli_query($conn, $sql); if (!$row = mysqli_fetch_assoc($result)) { echo "Username or password is incorrect"; } else { echo "You are logging in"; } //header("Location: index.php"); ?> Link to comment Share on other sites More sharing options...
dsonesuk Posted January 3, 2017 Share Posted January 3, 2017 (edited) LOOK carefully at pwd PART in sql statement does that look right to you? Edited January 3, 2017 by dsonesuk Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now