dongping1689 2018-06-19 09:56
浏览 68
已采纳

我尝试添加选项值时的SQL null值

Hello guys here is my form with php. Whole form is connected to MySQL. Everything work. But when I fill option value with input "zameranie", so it show in database like 0 value. All others values like name, password, email, gender work, but faculty and orientation don't.

Fakulta = faculty Zameranie = orientation

sorry for didn't translate in code. But I think there is no problem.

<!DOCTYPE HTML>
    <html>
    <head>
         <meta charset="UTF-8">
      <title>Form</title>
    </head>
    <body>
     <form action="insert.php" method="POST">
      <table>
       <tr>
        <td>Meno :</td>
        <td><input type="text" name="username" required></td>
       </tr>
       <tr>
        <td>Heslo :</td>
        <td><input type="password" name="password" required></td>
       </tr>
       <tr>
        <td>Pohlavie :</td>
        <td>
         <input type="radio" name="gender" value="m" required>Muž
         <input type="radio" name="gender" value="f" required>Žena
        </td>
       </tr>
       <tr>
        <td>Email :</td>
        <td><input type="email" name="email" ></td>
       </tr> 
       <tr>
        <td>Fakulta + zameranie</td>
        <td>
         <select name="fakulta" required>
          <option selected hidden value="">Fakulta</option>
          <option value="fri">FRI</option>
          <option value="fhv">FHV</option>
          <option value="sjf">SjF</option>
          <option value="pedas">PEDAS</option>
          <option value="svf">SvF</option>
          <option value="ef">EF</option>
         </select>
         <input type="text" name="zameranie" required>
        </td>
       </tr>
       <tr>
        <td><input type="submit" value="Submit"></td>
       </tr>
      </table>
     </form>
    </body>
    </html>

<?php
$username = $_POST['username'];
$password = $_POST['password'];
$gender = $_POST['gender'];
$email = $_POST['email'];
$fakulta = $_POST['fakulta'];
$zameranie = $_POST['zameranie'];
if (!empty($username) || !empty($password) || !empty($gender) || !empty($email) ||
!empty($fakulta) || !empty($zameranie)) {
 $host = "localhost";
    $dbUsername = "root";
    $dbPassword = "";
    $dbname = "youtube";
    //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 register Where email = ? Limit 1";
     $INSERT = "INSERT Into register (username, password, gender, email, fakulta, zameranie) 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("ssssii", $username, $password, $gender, $email, $fakulta, $zameranie);
      $stmt->execute();
      echo "Úspešne pridané do databázy";
     } else {
      echo "Niekto používa tento mail";
     }
     $stmt->close();
     $conn->close();
    }
} else {
 echo "Všetky položky sú povinné";
 die();
}
?>

Result in database when I fill form

Here is database

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 内存管理的一段代码不是很理解
      • ¥20 打开anaconda时卡在Loading applications无法进入界面
      • ¥15 网页超时时间设置失效
      • ¥15 有关绿色信贷毕业论文的问题
      • ¥30 关于#机器人#的问题,如何解决?
      • ¥15 求MATLAB函数ScalarLayerDisplay的代码
      • ¥15 安卓如何自动执行检测到的NFC标签,无需再点确认
      • ¥15 pyHM库mouse模块的ValueError错误
      • ¥15 python opencv 摄像头 传感器
      • ¥30 eMMC&Android&C&Linux