douxuan0698 2018-11-20 21:26
浏览 30

mysql和php,html表单[重复]

Hi I am writing code in a project where I am trying to make a registration form for an upcoming event.

I can't get the code to work. The data should be sent to the database but it doesn't. I get my own error, "Could not send form, send error".

How would you do it? The information should go from a html form to my mysql database via php. The "postalcode" must be hashed!

Could someone help?

(Pics to se the whole code as it should be... First, Second, Last)

My code:

<?php


    session_start();
    $_SESSION['message'] = '';
    $mysqli = new mysqli('serverip', 'trysil', 'mypass123', 'trysil');



    if ($_SERVER['REQUEST_METHOD'] == 'POST') {


     //Emails are matching
     if ($_POST['email'] == $_POST['email2']) {
        $firstname = $mysqli->real_escape_string($_POST['firstname']);
        $lastname = $mysqli->real_escape_string($_POST['lastname']);
        $personalnumber = md5($_POST['personalnumber']); //Hash:a Personnummer
        $gender = $mysqli->real_escape_string($_POST['gender']);
        $email = $mysqli->real_escape_string($_POST['email']);
        $phone = $mysqli->real_escape_string($_POST['phone']);
        $adress = $mysqli->real_escape_string($_POST['adress']);

          $_SESSION['firstname'] = $firstname;
          $_SESSION['lastname'] = $lastname;
          $_SESSION['personalnumber'] = $personalnumber;
          $_SESSION['email'] = $email;
          $_SESSION['phone'] = $phone;

          $sql = "INSERT INTO anmalningar ('firstname','lastname', 'personalnumber', 'email', 'phone', 'gender') VALUES ('$firstname', '$lastname', '$personalnumber', '$email', '$phone', '$gender')";

          if ($mysqli->query($sql) === true) {
            $_SESSION['message'] = "Det lyckades";
            header("location: welcome.php");

          }
          else {
            $_SESSION['message'] = "Could not send form, send error";
        }
   }
   else {
     $_SESSION['message'] = "Emails don't match";
   }

 }
 else {
   $_SESSION['message'] = "Not POST";

 }
 ?>

 <!DOCTYPE html>
 <html lang="en" dir="ltr">
   <body>
     <div class="">
       <?= $_SESSION['message'] ?>
     </div>
     <form class=""  method="post">
       <div style="border-bottom: 2px solid black;"  class="main-info">
         <h3 style="font-size:2vw;">Allmän Info</h3>
         <div class="firstname">
           <h4>Förnamn</h4>
           <input type="text" name="firstname" value="" required>
         </div>

         <div class="lastname">
           <h4>Efternamn</h4>
           <input type="text" name="lastname" value="" required>
         </div>

         <div class="personalnumber">
           <h4>Personnummer</h4>
           <input type="text" name="personalnumber" value="">
         </div>

         <div class="gender">
           <h4>Kön</h4>
           <input type="radio" id="man" name="gender" value="">
           <label for="man">Man</label><br>
           <input type="radio" name="gender" id="female" value="">
           <label for="female">Kvinna</label>
         </div>

         <div class="email">
           <h4>E-Post</h4>
           <input type="text" name="email" value=""><br>
           <h5>Verifiera E-Post</h5>
           <input type="text" name="email2" value="">
         </div>

         <div class="phone">
           <h4>Telefon</h4>
           <input style="margin-bottom:15px;" type="text" name="phone" value="">
         </div>
         </div>

         <br>
         <br>
         <div style="border-bottom: 2px solid black;"class="adress">
           <h3 style="font-size:2vw;">Adressinformation</h3>
           <h4>Gata och Husnummer</h4>
           <input type="text" name="adress" value="">
           <h4>Postkod</h4>
           <input type="text" name="postalcode" value="">
           <h4>Postort</h4>
           <input style="margin-bottom:15px" type="text" name="postalcity" value="">
         </div>

        <br>
        <br>
       <div style="border-bottom: 2px solid black;" class="parent-info">
         <h3 style="font-size:2vw;">Kontaktinformation, Vårdnadshavare</h3>
         <h4>Vårdnadshaves namn</h4>
         <input type="text" name="nameparent" value="">
         <h4>Vårdnadshaves E-Post</h4>
         <input type="text" name="emailparent" value="">
         <h4>Vårdnadshaves telefonnummer</h4>
         <input style="margin-bottom:15px;" type="text" name="phoneparent" value="">
       </div>
       <br>
<br>
      <div class="other">
        <h3 style="font-size:2vw;">Övrig info</h3>
        <h4>Allergier</h4>
        <input type="text" name="allergies" value="">
        <h4>Övrigt</h4>
        <input type="text" name="other" value="">
      </div>
      <input type="submit" name="submit" value="Skicka">
     </form>
   </body>
 </html>

Can someone spot the problem? Cause I certainty can't...

All the headers and names are in Swedish so don't worry.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?