Jump to content

undefined index


masterinex

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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