2014-03-05 81 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以后使用它们。