I have been using this script to add new users to my user_list table but I added some new fields to my form but really struggling to see how or where I allow the script to post the new fields.
<form method="POST" action="register.php">
<br>
<p><input name="user" type="text" placeholder="Username" /></p>
<p><input name="pass" type="password" placeholder="Password"/></p>
<br>
<p><input name="firstname" type="text" placeholder="First Name" /></p>
<p><input name="lastname" type="text" placeholder="Last Name" /></p>
<p><input name="email" type="text" placeholder="Ricoh Email Address" /></p>
<p><input name="ext" type="text" placeholder="Telephone Extension (e.g. 3312)" /></p>
<br>
<p><input type="submit" name="submit" value="Register User"></p>
</form>
</div>
<?
if(isset($_POST['submit'])){
include_once '../db_con.php';
include_once 'config.php';
if(isset($_POST['user'], $_POST['email']) && isset($_POST['pass'], $_POST['email'])){
$password=$_POST['pass'];
$sql=$dbh->prepare("SELECT * FROM user_login WHERE username= ? ");
$sql->execute(array($_POST['user']));
if($sql->fetchColumn()!=0){
die("User Exists");
}else{
function rand_string($length) {
$str="";
$chars = "subinsblogabcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen($chars);
for($i = 0;$i < $length;$i++) {
$str .= $chars[rand(0,$size-1)];
}
return $str;
}
$p_salt = rand_string(20);
$site_salt="subinsblogsalt";
$salted_hash = hash('sha256', $password.$site_salt.$p_salt);
$sql=$dbh->prepare("INSERT INTO `user_login` (`id`, `username`, `email`, `password`, `psalt`) VALUES (NULL, ?, ?, ?, ?);");
$sql->execute(array($_POST['user'], $salted_hash, $p_salt));
echo 'New user added';
}
}
}
?>
I tried to add the additional fields as $_POST['email'] etc etc as you can see but it says there is an error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens'
在$ sql-> execute()中添加$ _POST ['email']
$sql->execute(array($_POST['user'], $_POST['email'], $salted_hash, $p_salt));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.