2017-10-20 21 views
0

我製作了3頁:表單,數據庫連接和註冊頁面。我沒有收到任何錯誤,但是當我在表單頁面上註冊新用戶時,它並沒有在phpmyadmin儀表板上顯示。它看起來像我可以在我的表單頁上註冊一個新用戶,但沒有對phpmyadmin儀表板執行操作

請幫我

我該怎麼辦?

我的形式是在這裏:

<!DOCTYPE html> <html> <head> 
    <title></title>  <meta charset="utf-8"> </head> <body> <div 
style="background-color: #222; color: #fff; height: 50px; width: 
100%;"></div> <style type="text/css">  body{  background-color: 
#e1e1e1; }  form{   margin-top: 20px;   background-color: #fff; 

     }  form input{    padding: 4px;  } 

     button{    width: 100px;   height: 35px;   background-color: #222; 
      color: #fff;   margin-top: 10px;   border: 2px dotted;   } 
      </style> <form action="register.php" method="POST">   Forname:<br> <input type="text" name="first" id="first" 
size="50"><br>  Aftername:<br> <input type="text" name="last" 
size="50"><br>  E-post:<br>  <input type="text" name="email" 
size="50"><br>  Username:<br> <input type="text" name="username" 
size="50"><br>  Password:<br> <input type="password" name="password" 
size="50"><br> <button type="submit" name="submit" 
id="btn-submit">Sign Up</button> 

</form> </body> </html> 

我的數據庫連接:

<?php $conn = 
    mysqli_connect("127.0.0.1","root", "","test1"); if (!$conn) { 
     die("You can't connect to the database"); 

    } else echo "Your registration is succesed"; 

     ?> 

我的註冊頁面:

<?php require 'db.php'; ?> <?php 

    if(isset($_POST['submit'])){ session_start(); $hostname = 
    "127.0.0.1"; $username = "root"; $password = ""; $database = "login"; 

    $first = $_POST['first']; $last = $_POST['last']; $email = 
    $_POST['email']; $username = $_POST['username']; $password = 
    $_POST['password']; 


    $sql = $conn->query("INSERT INTO 
    users(first,last,email,username,password)values('{$first}','{$last}','{$email}','{$password}')"); 
    header('Location: login.php'); } 

    ?> 
+1

** **危險:你是**易受[SQL注入攻擊(HTTP:你需要[防守](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)。 – Quentin

+1

**危險**:「不哈希」是[不適合的哈希算法](http://php.net/manual/en/faq.passwords.php);你需要[更好地照顧](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet)你的用戶密碼。 – Quentin

回答

0

對於插入SQL,建議您顯示錯誤無論是否插入,例如w3school:PHP insert Data into MySQL

並可根據您的代碼,你錯過了$ username列值,替換這個和問題解決

$sql = "INSERT INTO users(first,last,email,username,password) 
     values('{$first}', '{$last}', '{$email}', '{$username}', '{$password}')"; 
if ($conn->query($sql) === TRUE) { 
    echo "New record created successfully"; 
} else { 
    echo "Error: " . $sql . "<br>" . $conn->error; 
} 
+0

哇,它的工作,非常感謝你的時間,並幫助「 –

相關問題