dongqia0240 2016-02-11 02:37
浏览 26
已采纳

php和mysql phpmyadmin数据库

In PHP MyAdmin I get this:


1.EMAIL | NAME

2."NAME"

3."EMAIL"

4."NAME"

5."EMAIL"

6."NAME"

7."EMAIL"

I want NAME to go to NAME column and EMAIL to go to EMAIL one.

Below is the code:

if($_POST['action']=="sub"){
    conndb($servername,$username,$password);
    namecheck($name);
    mailcheck($email);


    if (((empty($name)) || (empty($email))) || ((empty($name)) && (empty($email)))){
      echo "<p><strong>You have to fill the fields!</strong></p>";
    }
    else if ((mysqli_num_rows($name_result) < 1) && ( mysqli_num_rows ($email_result) < 1 )){
        $name_query="insert into stoixeia values (' ','$name')";
        mysqli_query($conn,$name_query) or die(mysql_error()) ;
        $email_query="insert into stoixeia values (' ','$email')";
        mysqli_query($conn,$email_query) or die(mysql_error()) ;
        echo "<p>Thank you for signing up!</p>";
    }
    else 
    {
        echo "<p>You are already subscribed!</p>";
    }
}
  • 写回答

1条回答 默认 最新

  • doumu9019 2016-02-11 02:42
    关注

    You need to do one INSERT statement, and specify which variables go in which column.

    $query = "INSERT INTO stoixea (name, email) VALUES ('$name', '$email')";
    mysqli_query($conn, $query) or die (mysqli_error($conn));
    

    Also, you can't use mysql_error() if you're using mysqli, you have to use mysqli_error().

    It would be best if you learned how to do prepared queries instead of substituting variables in the SQL. There are many tutorials, google it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?