我创建了这个函数来在单击提交按钮时更新数据库。但这似乎不起作用。该脚本旨在通过 id 使用用户的登录详细信息从数据库中提取用户的值并填充表单。该功能是在表单文本字段发生更改时帮助更新用户的详细信息。
请,我需要帮助调试它。
libraries.php
function db(){ //handles database connection
//connect to the database server or die and spit out connection error
$conn = mysql_connect('localhost','root', '') or die("Cannot connect to the database server now". mysql_error());
//select database table or die and spit out database selection error
mysql_select_db('newbishop',$conn) or die("Error in selecting database now ".mysql_errno());
return $conn;
}
personalsettings.php
<?php
include_once('libraries.php'); // contains the database function
session_checker();
db();
$categoryid = $_SESSION['id'];
$select = "SELECT * FROM users WHERE categoryid ='$categoryid' LIMIT 1";
$row1 = dbprocess ($select);
$rows = mysql_fetch_assoc($row1);
$pname1 = $rows['pname'];
$email1 = $rows['email'];
$user1 = $rows['user'];
$pass1 = $rows['pass'];
$salt1 = $rows['salt'];
$phone1 = $rows['phone'];
$accesslevel = $rows['accesslevel'];
$position = $rows['position'];
function update(){
db(); // database function
$pname = $_POST['pname'];
$categoryid = $_POST['categoryid'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$user = $_POST['users'];
$pass = $_POST['pass'];
function createSalt(){
$string = md5(uniqid(rand(), true));
return substr($string, 0, 3);
};
$salt = createSalt();
$hash = hash('sha256', $salt . $pass);
$sql = "UPDATE users SET user=?,pass=?,salt=?,pname=?,email=?,phone=? WHERE categoryid=?";
$q = $conn->prepare($sql);
$q->execute(array($user,$hash,$salt,$pname,$email,$phone,$categoryid));
}
?>
表单编辑个人设置
<input name="users" type="text" id="users" class="users" autocomplete="off" value="<?php echo $user1; ?>" />
<input type="text" autocomplete="off" name="pass" id="pass" placeholder="Create password" class="passwd" value="<?php echo $pass; ?>"/>
<input type="hidden" name="salt" id="salt" value="<?php echo $salt1; ?>"/>
<input name="pname" type="text" id="lname" placeholder="Name of Group" class="input-block-level" value="<?php echo $pname1; ?>"/>
<input type="hidden" id="categoryselect" name="categoryselect"/>
<input name="categoryid" type="text" id="resultselect" readonly class="input-block-level" value="<?php echo $_SESSION['id']; ?>"/>
<input type="text" name="email" id="email" placeholder="Email Address" class="input-block-level" value="<?php echo $email1; ?>"/>
<input type="text" name="phone" id="phone" placeholder="Enter Phone Number" class="input-block-level" value="<?php echo $phone1; ?>"/>
<input type="text" name="accesslevel" id="accesslevel" class="input-block-level" value="<?php echo $accesslevel; ?>" readonly/>
<input type="text" name="position" id="position" class="input-block-level" value="<?php echo $position; ?>" readonly/>
<button type="submit" class="btn btn-small btn-primary" name="register" id="register" value="Register" onclick="update()">Submit</button>
</form>