Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have an error it says
Notice: Undefined index: email in C:\xampp\htdocs\finale\register.php on line 22


here's my code.

What I have tried:

connect.php
PHP
<?php
mysql_connect('localhost','root','') or  die('cant connect database ');
mysql_select_db("forumseries") or die('cannot select database');
?> 

register.php
HTML
<form action="register.php" method="post">
username:<input type="text" name="username"><br>

email:<input type="text" name="email"><br>

password:<input type="text" name="password"><br>
<input type="submit"name="submit">
  </form>
PHP
<?php
include_once('connect.php');
if(isset($_POST['submit'])){
    $username=$_POST['username'];
    $email=$_POST['email'];
    $password=$_POST['password'];
    if(!empty($username)&&!empty($email)&&!empty($password)){
        $sql=mysql_query("select * from users");
        while ($row=mysql_fetch_array($sql)) {
            $user=$row['username'];
            $eml=$row['email'];
            if($user!=$username&&$eml!=$email){
                $sql2=mysql_query("insert into users(id,username,email,password)values('$username','$email','$password')");
            }
        }
    }else{
        echo"All fields required";   }
}
?>
Posted
Updated 15-Jul-20 2:34am
v3
Comments
Jochen Arndt 27-Mar-17 8:08am    
Why you are showing connect.php which is not related to the question and posted the HTML code that calls register.php?

To get help you should post the relevant code portions of register.php and how it is called (that is there but should be indicated like register.html).
Jim Clinton 27-Mar-17 8:10am    
sorry it's a typo



username:

email:

password:


<?php
include_once('connect.php');
if(isset($_POST['submit'])){
$username=$_POST['username'];

$email=$_POST['email'];

$password=$_POST['password'];
if(!empty($username)&&!empty($email)&&!empty($password)){
$sql=mysql_query("select * from users");
while ($row=mysql_fetch_array($sql)) {
$user=$row['username'];
$eml=$row['email'];
if($user!=$username&&$eml!=$email){
$sql2=mysql_query("insert into users(id,username,email,password)values('$username','$email','$password')");
}
}

}else{
echo"All fields required"; }

}
?>
Jochen Arndt 27-Mar-17 8:15am    
You seem to have problems with the editor. I will try to "unhide" the code.

Is this line 22
$eml=$row['email'];
?

Then your table might not have a column "email".
Bryian Tan 27-Mar-17 23:19pm    
Just curious, is this right? Passing three value into the table, but the table expecting 4 values.

insert into users(id,username,email,password)
values('$username','$email','$password')")

1 solution

In line 8 use mysqli_query then you get the result
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900