2012-06-22 74 views
0

我正在使用isset函數來檢查提交按鈕是否被點擊,但它不起作用。它沒有輸入if。這是我的代碼。我沒有得到問題仍然存在的地方。isset提交不起作用

<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
     <td><h2><br /> 
      User Registration</h2> 
      <p>&nbsp;</p></td> 
    </tr> 
    <tr> 
     <td> 
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1" onsubmit="return Validate();"> 
       User Name[E-mail ID]: <input type="text" name="username" style="width:230px; height:20px;" /><br /><br /> 
       Password : <input type="password" name="password" style="width:230px; height:20px;" /><br /><br /> 
       Name <input type="text" name="name" style="width:230px; height:20px;" /><br /><br /> 
       Contact Number: <input type="text" name="phone" style="width:230px; height:20px;" /><br /><br /> 
       Email: <input type="text" name="email" style="width:230px; height:20px;" /><br /><br /> 
       <input type="submit" value="REGISTER" /> 
      </form> 

      <?php 
      include('connect.php'); 
      if (isset($_POST['submit'])) 
      { 
       echo "1"; 
       $username = $_POST['username']; 
       echo $username; 

       $password = $_POST['password']; 
       $name = $_POST['name']; 
       $phone = $_POST['phone']; 

       $email = $_POST['email']; 
       //$id = $_GET['aid']; 

       $sql = "INSERT INTO user_info(application_id, username, password, name, contact, email) VALUES (" . $aid. ", " .$username.", ".$password.", ".$name.",". $phone.", ".$email.") "; 
       echo $sql; 
       mysql_query($sql) or die(mysql_error()); 
       //header("Location: index1.php"); 
      } 

      ?> 

     </td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
    </tr> 
</table> 

請讓我知道我要去哪裏錯了。

+0

我認爲你的HTML是錯誤的(你沒有提供提交字段元素的名稱屬性)。你需要這樣的東西:''在PHP中,您需要調用'isset($ _ POST ['mysubmit'])' –

回答

2

變化

<input type="submit" value="REGISTER" /> 

<input type="submit" name="submit" value="REGISTER" /> 
+0

非常感謝您所有的答覆。僅僅因爲我錯過了提交的名字而愚蠢的錯誤。對不起,寶貴的時間。但是,謝謝一噸 – user1321271

1

您需要提供name屬性的提交按鈕

<input type="submit" name="submit" value="REGISTER" /> 
1

您需要的submit名稱的輸入元素。

你可以給你的提交按鈕這個名字,例如

<input type="submit" value="REGISTER" name="submit" /> 

,或者你可以創建一個名稱,而不是一個隱藏的輸入:

if (count($_POST) > 0) 
{ 
    //code 
} 

這應該只火了:

<input type="hidden" name="submit" /> 
0

如果窗體已經公佈回來你可以改爲測試如果至少有一個域已被回發。