2014-12-06 108 views
2

要插入数据库的PHP代码。代码有时不起作用。大多数时候它确实有效。插入查询有时不起作用

<?php 
    include 'connection.php'; 
    if (isset($_POST['docsignup'])) 
    { 

     // prepare and bind 
     $stmt = $link->prepare("INSERT INTO doctor_details(firstname, lastname, license_num, zip_code, city, state, email, password, speciality) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); 
     $stmt->bind_param("ssissssss", $docfname, $doclname, $docid, $doczipcode, $city, $state, $docemail, $hash, $speciality); 

     // set parameters and execute 
     $docfname = $_POST['docfname']; 
     $doclname = $_POST['doclname']; 
     $docemail = $_POST['docemail']; 
     $docloginpassword = $_POST['docloginpassword']; 
     $docid = $_POST['docId']; 
     $speciality = $_POST['speciality']; 
     $city = $_POST['city']; 
     $state = $_POST['state']; 
     $doczipcode = $_POST['doczipcode']; 

     // A higher "cost" is more secure but consumes more processing power 
     $cost = 10; 

     // Create a random salt 
     $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.'); 

     // Prefix information about the hash so PHP knows how to verify it later. 
     // "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter. 
     $salt = sprintf("$2a$%02d$", $cost) . $salt; 

     // Value: 
     // $2a$10$eImiTXuWVxfM37uY4JANjQ== 

     // Hash the password with the salt 
     $hash = crypt($docloginpassword, $salt);  

     $stmt->execute(); 

     echo "New records created successfully"; 

     $stmt->close(); 
     $link->close(); 

    } 
    ?> 

connection.php

<?php 
$link = mysqli_connect("localhost","root","","cl10-doctor"); 
?> 

当我使用的密码字段上来说,我已经注意到了代码does not工作。

我做错了吗?

+0

用户名和密码区分大小写。 – 2014-12-06 09:45:35

+0

@MarcoMura该评论没有帮助..当密码包含大写字母时,为什么不插入到数据库中。 – 2014-12-06 09:47:54

+0

以小写或大写形式存储您的密码。 – 2014-12-06 09:49:06

回答

1

不要让它区分大小写。让用户键入他/她想要的任何东西,但在后台将其转换为大写或小写。

密码以不可读的格式存储在数据库中,因此无论是大写还是小写都不会有任何问题。

使用PHP strtolower()以小写转换密码并将其存储在数据库中

at符号的重复时做上述相同。