Jump to content

PHP Error - NOTICE: Undefined index


Recommended Posts

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 post
Share on other sites

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

  • Like 1
Link to post
Share on other sites

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