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.

 

Edited by cyberRobot
separated code blocks
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.

Edited by cyberRobot
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

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