undefined index error in mysql query

后端 未结 4 601
时光取名叫无心
时光取名叫无心 2020-12-20 10:44


        
4条回答
  •  無奈伤痛
    2020-12-20 11:06

    Put the mysql query in the if statement curly braces just like this:

    if(isset($_POST['submit'])) {
    $name1=$_POST['name'];
    $phone1=$_POST['phone'];
    $email1=$_POST['email'];
    $pass1=$_POST['password'];
    $query="INSERT INTO `register`(`name`,`phone`,`email`,`pass`) VALUES('$name1','$phone1','$email1','$pass1')";
    $result=mysql_query($query) or die("Error in pushing".mysql_error());
    mysql_close($conn);
    }
    ?>
    

    When the form isn't submited, your variables are not defined and you are querying the db with them. So you put everything in the if statement, so that only when the form is submitted that the query will execute. Also you are vulnerable to mysql injection, use the mysql_real_escape_string function or use mysqli prepared statement.

提交回复
热议问题