2014-03-05 62 views
-1

從我的形式獲取數據我有PHP代碼的問題,我想從我的HTML表單讀取數據和我不斷收到空 這裏是我的PHP代碼不能使用PHP _ POST方法

<html> 
<body> 
    <?php 
     $dbhost="127.0.0.1"; 
     $dbuser="root"; 
     $dbpass=""; 
     $dbname="mss"; 
     $connection=mysql_connect($dbhost,$dbuser,$dbpass,$dbname); 
     if(mysql_errno()) { 
      die("Database Connection failed:" . mysql_error() . "(" . mysql_errno() .")");  
     } 
    ?> 
    first Name : <?php if($_SERVER['REQUEST_METHOD'] == "POST"){ $first = $_REQUEST['firstName']; echo $first; } ?><br> 
    last Name : <?php $last = (isset($_REQUEST['lastName']) ? $_REQUEST['lasttName']: "hello"); echo $last; ?><br> 
    email : <?php $email = (isset($_REQUEST['email']) ? $_REQUEST['email']: "hello"); echo $email; ?><br> 
    street address : <?php $streetAddress = (isset($_REQUEST['streetAddress']) ? $_REQUEST['streetAddress']: "hello"); echo $streetAddress; ?><br> 
    city : <?php $city = (isset($_REQUEST['city']) ? $_REQUEST['city']: "hello"); echo $city; ?><br> 
    state : <?php $state = (isset($_POST['state']) ? $_POST['state']: "hello"); echo $state; ?><br> 
    Zip code : <?php $zipCode = (isset($_POST['zipCode']) ? $_POST['zipCode']: "hello"); echo $zipCode; ?><br> 
    college : <?php $college = (isset($_POST['college']) ? $_POST['college']: "hello"); echo $college; ?><br> 
    userName : <?php $username = (isset($_POST['username']) ? $_POST['username']: "hello"); echo $username; ?><br> 
    password : <?php $password = (isset($_POST['password']) ? $_POST['password']: "hello"); echo $password; ?><br> 
</body> 

和下面是形式

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Add New Employee</title> 
    <script type="text/javascript" src="new employee validate.js"></script> 
</head> 
<body> 
    <h1 style="font-family:Verdana, Geneva, sans-serif; font-size:24px;" align="center">Add New Employee</h1> 
    <form name="AddNewEmployee" onSubmit="return validation()" action="AddEmployeePhp.php" method= "POST"> 
     <table align="center"> 
      <tr> 
       <td><font color="#FF0000">*</font> First Name:</td> 
       <td><input type="text" id="firstName" name ="firstName" required = "required"/></td> 
      </tr> 
      <tr> 
       <td><font color="#FF0000">*</font>Last Name:</td> 
       <td><input type="text" id="lastName" name ="lastName" required = "required"/></td> 
      </tr> 
      <tr> 
       <td><font color="#FF0000">*</font>E-mail Address:</td> 
       <td><input type="text" id="email" name="email" required = "required"/></td> 
      </tr> 
      <tr> 
       <td><font color="#FF0000">*</font>Cell Phone Number:</td> 
       <td><input type="text" id="phone" name="phone" required = "required"/></td> 
      </tr> 
      <tr> 
       <td>Street Address:</td> 
       <td><input type="text" id="streetAddress" name= "streetAddress"/></td> 
      </tr> 
      <tr> 
       <td>City:</td> 
       <td><input type="text" id="city" name = "city"/></td> 
      </tr> 
      <tr> 
       <td>State:</td> 
       <td><input type="text" id="state" name ="state"/></td> 
      </tr> 
      <tr> 
       <td>Zip Code:</td> 
       <td><input type="text" id="zipCode" name="zipCode"/></td> 
      </tr> 
      <tr> 
       <td>College:</td> 
       <td><input type="text" id="college" name="college"/></td> 
      </tr> 
      <tr> 
       <td><font color="#FF0000">*</font>User Name:</td> 
       <td><input type="text" id="username" name = "username" required = "required"/></td> 
      </tr> 
      <tr> 
       <td><font color="#FF0000">*</font>Password:</td> 
       <td><input type="password" id="password" name = "password" required = "required"/> </td> 
      </tr> 
      <tr> 
       <td><font color="#FF0000">*</font>Confirm Password:</td> 
       <td><input type="password" id="confirmPassword" required = "required"/></td> 
      </tr> 
      <tr> 
       <td> 
        <p>&nbsp;</p> 
       </td> 
       <td> 
        <p>&nbsp;</p> 
       </td> 
      </tr> 
      <tr> 
       <td><input type="submit" name="Create Employee" value="Create Employee"/></td> 
       <td><input type="button" name="Clear All" value="Clear All" /></td> 
      </tr> 
     </table> 
    </form> 
    &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
    <label> Note: All <font color="#FF0000">*</font> Fields are required please fill them all</label> 
</body> 

任何SUG我的HTML代碼gestions?

+0

請粘貼後考慮格式化您的代碼!現在你到底在哪裏? – FAS

+1

你有沒有嘗試'var_dump($ _ SERVER ['REQUEST_METHOD'],$ _POST)'? –

+0

我有點難以閱讀所有這些混亂的代碼。我的眼睛正在爭取從左到右。 –

回答

1

這有一個錯字$_REQUEST['lasttName']這應該是$_REQUEST['lastName']

另外,這<input type="password" id="confirmPassword" required = "required"/>沒有其他參考吧,所以我不確定爲什麼你使用/,包括它。

我也沒有在onSubmit="return validation()"中看到validation()函數的任何引用,所以如果你沒有它的功能(我沒有在你的發佈代碼中看到),那麼你需要刪除它。

我注意到的另一件事是有幾個命名錶單元素包含空格;那是無效的。

即:你有name="Create Employee"使用下劃線name="Create_Employee"name="Clear All"name="Clear_All"如果你決定在你的PHP以後使用它們。