我对此很新,所以请耐心等待。我正在尝试创建一个登录用户可以更新数据库中的信息行的页面。我一直坐在这里几个小时试图解决这个问题,所以也许有人可以帮助解决这个问题。现在我甚至得到一个空白的白页,无法找出原因。
<?php
require_once('auth.php');
require_once('config.php');
$errmsg_arr = array();
$errflag = false;
//Connect to mysql server
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$conn) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Create query
$qry="SELECT * FROM members WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
$_SESSION['SESS_EMAIL'] = $member['email'];
session_write_close();
//header("location: index.php");
exit();
}
}else {
die("Query failed");
}
?>
然后我试图以我创建的表单中的查询结果显示为框中已有的默认值。据我所知,它应该是这样的?
<input name="fname" type="text" class="textfield" id="fname" value="<?php echo $member['member_id'] ?>"/>
从那里我想传递新数据,以便我可以编写更新sql语句。
或者,如果您有某种资源可以帮助我以简单的方式向我解释,我真的很感激。
答案 0 :(得分:3)
成功查询后,您正在调用exit()
。如果继续显示结果,则脚本已经终止。
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
$_SESSION['SESS_EMAIL'] = $member['email'];
//header("location: index.php");
// Don't call exit()!
// Remove this!
exit();