0
votes

I have made i Registre page but get this :

How do i fix it?

... Notice: Undefined index: _name in C:\wamp\www\paperblog\signup.php on line 2

Notice: Undefined index: _username in C:\wamp\www\paperblog\signup.php on line 3 ...

<?php
$name=$_POST['_name'];
$username=$_POST['_username'];
$gender=$_POST['_gender'];
$email=$_POST['_email'];
$password=$_POST['_password'];
$repassword=$_POST['_repassword'];
$question=$_POST['_question'];
$answer=$_POST['_answer'];
$sql="INSERT INTO members ('name', 'gender', 'city', 'email', 'username', 'password', 'question', 'answer') VALUES ('$name','$username',$gender','$email','$password','$question','$answer')";
include_once("header.html");
$localhost="localhost";
$db_user="root";
$db_password="";
$db_name="blog";
$connect=mysqli_connect("localhost","root","");
mysqli_select_db($connect,"blog");
include_once("header.html");
$msg='';
if ( isset( $_POST['submit'] ) ) 
           if ( empty( $username ) )
           $msg .='<br>Username Required</br>' ;
    else if ( empty( $password ))
           $msg .='Password is Required';
    else if ( $password != $repassword)
           $msg .='Password Mismatch';
                   else {
                    mysql_query($sql);

                   }

?>
1
You need to set up all your variables inside your condition if(isset($_POST['submit'])). You are also missing the brackets as you don't have only one instruction in it.D4V1D
@D4V1D is absolutely right. you just both ignore the fact that PHP already tells you that your POST variables are missing keys that you expect to be there, as well as you ignore that these values need to come from somewhere -- see my (hopefully a bit more diplomatic) answer.Marcus Müller

1 Answers

1
votes

Your error message is already telling you what goes wrong: There's simply no _name in $_POST. I guess that you meant to supply these things using a HTML <form>, so maybe you forgot to make fields for that?

Anyway, you just rely on your user input, which is a security and stability hazard deluxe. You must always first check whether the data that comes from the browser of your user is what you expect, otherwise terrible things might happen.

You $sql is something that your PHP/sql tutorial should have told you never to do. Read this comic and then write a one-page essay about what you did wrong, please!