누구든지 내 코드가 내 테이블에 등록 자격 증명을 두 번 삽입하는 이유를 볼 수 있습니까? action_registration.php
. 나는 현재 로그인을 더 안전하게하는 법을 배우고 있는데, 등록을위한 입력이 테이블에 두 번 삽입되었다는 것을 알아 차렸다.등록시 자격 증명 복제
<?php
if (isset($_POST['register'])){
// connection handler link
$conreg = new mysqli('localhost', 'x', '123456', 'db.x.x');
// in case theres no link to connection
if (mysqli_connect_error()){
echo mysqli_connect_error();
exit();
} // end error if
else // when connection is okay
{
echo "we good on connection so far";
echo "<br>";
} // end else connection okay
$userreg = $_POST['username'];
$passreg =$_POST['password'];
$phash = sha1(sha1($passreg."salt")."salt");
$emailreg = $_POST['email'];
$sqlreg = "INSERT INTO tbl1 (`username` , `password`, `email` , `comment_value`, `Member_Since`) VALUES (?,?,?,'1' , now()) ";
// prepare link, and function statement
$stmtreg = $conreg->prepare($sqlreg);
// bind variable parameters
mysqli_stmt_bind_param($stmtreg, "sss", $userreg , $phash , $emailreg); // bind variables s' is a string for username , s' is a string for password
if (!mysqli_execute($stmtreg))
{
echo "Died on bind variable parameters";
die('stmt error: '.mysqli_stmt_error($stmtreg));
} // end error if
mysqli_stmt_execute($stmtreg); //excute the preapared register statement
//$cookie_value = $user;
//setcookie($cookie_name , $cookie_value, time() + (2000), "/");
//header("Location: reg_.php");
echo '<font color="green">Please Login Now</font>';
} // end isset register
?>
양식은 action_registration.php
호출
<table>
<form action ="actions/action_registration.php" method="POST" >
<tr>
<td> Username :</td>
<td><input type="text" placeholder="Username" id="username" name="username"> </td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" placeholder="Password" id="password" name="password" > </td>
</tr>
<tr>
<td> Email :</td>
<td><input type="text" placeholder="Email"id="email" name="email" size="20"/></td>
<br/>
</tr>
<tr>
<td><td>
<input type="submit" name="register" value="Register"></td> </tr>
</table>
</form>
실행 쿼리를 두 번 1)'mysqli_execute()', 2)'mysqli_stmt_execute ($의 stmtreg)'과 :
당신은 아마뿐만 아니라
mysqli_stmt_execute
를 사용하는 첫번째 전화를 변경해야는mysqli_execute
단지의 별칭입니다 잘'mysqli_execute()'는 더 이상 사용되지 않으며 제거 될 것이다. CHECK http://php.net/mysqli_execute – Saty