masterinex Posted August 25, 2017 Share Posted August 25, 2017 (edited) when i run this code , i am getting undefined index for password , phonenumber and nickname. form1.html: <html> <body> <form action="welcome.php" method="post"> E-mail: <input type="text" name="email"><br> Password: <input type="text" name="password"><br> Nickname: <input type="text" name="nickname"><br> Phonenumber: <input type="text" name="phonenumber"><br> <input type="submit"> </form> </body> </html> welcome.php: <html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo $_POST["email"]; ?> <?php //Step1 $db = mysqli_connect('localhost','root','','users') or die('Error connecting to MySQL server.'); ?> <html> <head> </head> <body> <h1>PHP connect to MySQL</h1> <?php $email = $_POST['email']; $password = $_POST['password']; $phonenumber = $_POST['phonenumber']; $nickname = $_POST['nickname']; $sql ="INSERT INTO users (email,password,nickname,phonenumber) VALUES ('$email','$password','$nickname' , '$phonenumber' )"; mysqli_query($db,$sql); //Step2 $query = "SELECT * FROM users"; mysqli_query($db, $query) or die('Error querying database.'); //Step3 $result = mysqli_query($db, $query); //$row = mysqli_fetch_array($result); while ($row = mysqli_fetch_array($result)) { echo $row['email'] . ' ' . $row['password'] . ' '. $row['nickname'] . ' '. $row['phonenumber'] .'<br />'; } //Step 4 mysqli_close($db); ?> </body> </html> when i run this code , i am getting undefined index for password , phonenumber and nickname. Edited August 28, 2017 by cyberRobot separated code blocks Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 25, 2017 Share Posted August 25, 2017 (edited) Assuming that the error message is coming from the code at "step 3", why is your fetch commented out? And - what is the point of the code at step 2??? Edited August 25, 2017 by ginerjm Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 28, 2017 Share Posted August 28, 2017 (edited) What are you looking to do? Is this a registration / sign-up form? Is it to log in? If you're not doing so already, you need to look into password hashing. More information can be found here: http://php.net/manual/en/faq.passwords.php Assuming that the error message is coming from the code at "step 3", why is your fetch commented out? There's another fetch in the while loop. Edited August 28, 2017 by cyberRobot Quote Link to comment Share on other sites More sharing options...
requinix Posted August 28, 2017 Share Posted August 28, 2017 Make sure you are not going to welcome.php directly or through a link. Have to use the form in form1.html to get there. Which isn't good, but that's how you have it set up for now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.