2014-03-07 52 views
0

我已經使用自舉直列形式。下面的代碼:引導表單提交用PHP表示錯誤

<form class="form-inline" action="php/signup.php" method="post"> 
       <div class="form-group"> 
        <label class="sr-only" for="firstname">First name</label> 
        <input type="text" required class="form-control" id="exampleInputEmail2" name="firstname" placeholder="First name"> 
       </div> 
       <div class="form-group"> 
        <label class="sr-only" for="middlename">Middle name</label> 
        <input type="text" class="form-control" id="exampleInputEmail2" name="middlename" placeholder="Middle name"> 
       </div> 
       <div class="form-group"> 
        <label class="sr-only" for="lastname">Last name</label> 
        <input type="text" required class="form-control" id="exampleInputPassword2" name="lastname" placeholder="Last name"> 
       </div> 


       <br/> 
       <br/> 

       <div class="form-group"> 
        <label class="sr-only" for="username">User name</label> 
        <input type="text" required class="form-control" id="exampleInputPassword2" name="username" placeholder="Desired user name"> 
       </div> 

       <br/> 
       <br/> 

       <div class="form-group"> 
        <label class="sr-only" for="password">Password</label> 
        <input type="password" required class="form-control" id="exampleInputPassword2" name="password" placeholder="Password"> 
       </div> 

       <br/> 
       <br/> 

       <div class="form-group"> 
        <label class="sr-only" for="repassword">Re enter password</label> 
        <input type="password" required class="form-control" id="exampleInputPassword2" name="repassword" placeholder="Re enter password"> 
       </div> 

       <br/> 
       <br/> 

       <div class="form-group"> 

        <input type="email" required class="form-control" id="exampleInputPassword2" name="email" placeholder="E-mail address"> 
       </div> 

       <br/> 
       <br/> 

       <button type="submit" name="btnSubmit"> Sign up</button> 
     </form> 

我也提交表單數據的PHP後端:

<?php 
session_start(); 
include("connect_to_mysql.php"); 
if(isset($_POST("btnSubmit"))) 
{ 
    $firstname = mysql_real_escape_string($_POST("firstname")); 
    $middlename = mysql_real_escape_string($_POST("middlename")); 
    $lastname = mysql_real_escape_string($_POST("lastname")); 
    $username = mysql_real_escape_string("username"); 
    $password = mysql_real_escape_string("password"); 
    // check the re entered password using jquery on the client machine itself 
    $email = mysql_real_escape_string("email"); 


    /*firstname varchar(255), 
       middlename varchar(255) NOT NULL, 
       lastname varchar(255) NOT NULL,*/ 
    $query = "create table if not exists authenlist(
       id int NOT NULL AUTO_INCREMENT, 
       username varchar(255) NOT NULL, 
       password varchar(255) NOT NULL, 
       PRIMARY KEY (id))"; 

    $i = mysql_query($query) or die("authentication table not created"); 

    if($i) 
    { 
     $query = "select * from authenlist where username='$username'"; 

     $o = mysql_query($query) or die("query not executed"); 

     if($o) 
     { 
      if(mysql_num_rows($o) == 0) 
      { 
       $query = "insert into authenlist values('', '$username', '$password')"; 
       $_SESSION['username']=$username;//to register user 
       header("location:home.php"); 
       exit(); 
      } 
      else 
      { 
       header("status: 404 not found"); 
      } 
     } 
    } 
} 
?> 

當我嘗試提交表單總有一個致命的錯誤:致命錯誤:無法使用函數返回值在第4行的C:\ wamp \ www \ the_unknown \ php \ signup.php中的寫入上下文中。

我無法理解表單提交過程中的錯誤。 我現在需要這種形式,我真的需要它的工作。 請有人幫我解決我面臨的問題。 在此先感謝。

+0

有啥在您signup.php 4號線? –

+0

並且請不要使用mysql函數,它們將在下一個主要版本中被移除......(希望)。使用PDO或至少mysqli的 –

+0

@DrixsonOseña如果(isset($ _ POST( 「btnSubmit按鈕」))) –

回答

3

$_POST("btnSubmit")是錯誤的

使用

$_POST["btnSubmit"] 

這是任何陣列

+0

太感謝你了.... –

+0

如果這個工作,爲什麼不標出答案接受;) – noobcode