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.

         <meta charset="UTF-8">
     <form action="insert.php" method="POST">
        <td>Meno :</td>
        <td><input type="text" name="username" required></td>
        <td>Heslo :</td>
        <td><input type="password" name="password" required></td>
        <td>Pohlavie :</td>
         <input type="radio" name="gender" value="m" required>Muž
         <input type="radio" name="gender" value="f" required>Žena
        <td>Email :</td>
        <td><input type="email" name="email" ></td>
        <td>Fakulta + zameranie</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>
         <input type="text" name="zameranie" required>
        <td><input type="submit" value="Submit"></td>

$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);
     $rnum = $stmt->num_rows;
     if ($rnum==0) {
      $stmt = $conn->prepare($INSERT);
      $stmt->bind_param("ssssii", $username, $password, $gender, $email, $fakulta, $zameranie);
      echo "Úspešne pridané do databázy";
     } else {
      echo "Niekto používa tento mail";
} else {
 echo "Všetky položky sú povinné";

Result in database when I fill form

Here is database

  • 写回答



      相关推荐 更多相似问题


      • ¥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