需要关于如何将数据从html表单添加到数据库的建议吗

wdebmtf2  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(294)

这个问题在这里已经有答案了

500 php文件的内部服务器错误不适用于html[重复](6个答案)
如何显示mysqli查询的错误[重复](2个答案)
两年前关门了。
我不知道我做错了什么,一直在说HTTP500错误。我想做一份企业登记表。必须添加:介绍,企业名称,行业,街道地址1,街道地址2,城市,代码,公司注册号,增值税号码,电子邮件和电话。我已经编写了html注册表单和php文件以连接到数据库,但是什么都不起作用。我真的需要关于如何解决这个问题的建议。
我的html表单代码:

<!DOCTYPE HTML>
<html>
<head>
  <title>Register Form</title>
</head>
<body>
 <form action="insert1.php" method="POST">
  <table>
   <tr>
    <td>Referral :</td>
    <td><input type="text" name="referral" required></td>
   </tr>
   <tr>
    <td>Business Name :</td>
    <td><input type="text" name="busname" required></td>
   </tr>
   <tr>
    <td>Industry :</td>
    <td><input type="text" name="industry" required></td>
   </tr>
   <tr>
    <td>Street Address :</td>
    <td><input type="text" name="streetAddress1" required></td>
   </tr>
   <tr>
    <td>Street Address 2 :</td>
    <td><input type="text" name="streetAddress2"></td>
   </tr>
   <tr>
   <td>City: </td>
   <td><input type="text" name="city" required/></td>
   </tr>
   <tr>
    <td>Code :</td>
    <td>
     <input type="text" name="code" required>

    </td>
    </tr>
   <tr>
    <td>Company registration No :</td>
    <td><input type="text" name="regNo" required></td>
   </tr>
   <tr>
    <td>VAT no :</td>
    <td><input type="text" name="vat" required></td>
   </tr>

   <tr>
    <td>Email :</td>
    <td><input type="email" name="email" required></td>
   </tr> 
   <tr>
    <td>Phone no :</td>
    <td>

     <input type="phone" name="phone" required>
    </td>
   </tr>
   <tr>
    <td><input type="submit" value="Submit"></td>
   </tr>
  </table>
 </form>
</body>
</html>

php文件:

<?php
$referral = filter_input(INPUT_POST,'referral');
$busName = filter_input(INPUT_POST,'busname');
$industry = filter_input(INPUT_POST,'industry');
$streetAddress1 = filter_input(INPUT_POST,'streetAddress1');
$streetAddress2 = filter_input(INPUT_POST,'streetAddress2');
$city = filter_input(INPUT_POST,'city');
$code = filter_input(INPUT_POST,'code');
$regNo = filter_input(INPUT_POST,'regNo');
$vat = filter_input(INPUT_POST,'vat');
$email = filter_input(INPUT_POST,'email');
$phone = filter_input(INPUT_POST,'phone'];

if (!empty($referral) || !empty($busName) || !empty($industry) || !empty($streetAddress1) || 
!empty($city) || !empty($code) || !empty($regNo) || !empty($vat) || !empty($email) !empty($phone)) {
 $host = "localhost";
    $dbUsername = "sdlmembe_4fin";
    $dbPassword = "@2b4Stef1";
    $dbname = "sdlmembe_4fin";
    //create connection
    $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
    if (mysqli_connect_error()) {
     die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
    } else {
     $SELECT = "SELECT email From 4finmembers Where email = ? Limit 1";
     $INSERT = "INSERT Into 4finmembers (referral, busname, industry, streetAddress1, streetAddress2, city, code, regNo, vat, email, phone) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
     //Prepare statement
     $stmt = $conn->prepare($SELECT);
     $stmt->bind_param("s", $email);
     $stmt->execute();
     $stmt->bind_result($email);
     $stmt->store_result();
     $rnum = $stmt->num_rows;
     if ($rnum==0) {
      $stmt->close();
      $stmt = $conn->prepare($INSERT);
      $stmt->bind_param("ssssssssssi", $referral, $busName, $industry, $streetAddress1, $streetAddress2, $city, $code, $regNo, $vat, $email, $phone);
      $stmt->execute();
      echo "New record inserted sucessfully";
     } else {
      echo "Someone already register using this email";
     }
     $stmt->close();
     $conn->close();
    }
} else {
 echo "All field are required";
 die();
}
?>

将其添加到sql数据库时,数据库中的name字段的拼写必须与name=“email”完全相同。或者我可以在数据库里把它改成“email address”。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题