我正在尝试制作书写板,并且当作者完成保存时需要在DB中保存ID值。 但我的数据库只显示'0'member_idx,它看起来我的id会话maintating现在正在工作。 我附上了我的相关代码,但如果您需要更多我错过的代码,请告诉我。
_这是我在apache2的htdocs下的work_tree enter image description here
这是login_check.php
<?php
session_start();
include_once ('../config.php');
$mysqli = new mysqli($DB['host'], $DB['id'], $DB['pw'], $DB['db']);
if (mysqli_connect_error()) {
exit('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
}
extract($_POST);
$q = "SELECT * FROM ap_member WHERE id='$user_id'";
$result = $mysqli->query($q);
if($result->num_rows==1) {
$encrypted_pass = sha1($user_pass);
$row = $result->fetch_array(MYSQLI_ASSOC);
if( $row['pw'] == $encrypted_pass ) {
$_SESSION['member_idx'] = $row['member_idx'];
header('Location: '.$url['root'].'login_done.php');
}
else {
echo 'wrong password';
}
}
else {
echo 'ID does not exist or invalid approach. Try again.';
}
if( $row['pw'] == $encrypted_pass ) {
$_SESSION['is_logged'] = 'YES';
$_SESSION['user_id'] = $user_id;
$_SESSION['member_idx'] = $row['member_idx'];
header('Location: '.$url['root'].'login_done.php');
exit();
}
else {
$_SESSION['is_logged'] = 'NO';
$_SESSION['user_id'] = '';
header('Location: '.$url['root'].'login_done.php');
exit();
}
?>
_这是write.php
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/preset.php';
include $_SERVER['DOCUMENT_ROOT'].'/header.php';
?>
Write a Commment for anything please <br />
<form name ="write_form" method = "POST" action = "./write_check.php">
<input type="hidden" name="member_idx" value="<?php echo $_SESSION['member_idx'] ?>">
<table>
<tr>
<td>
Title
</td>
<td>
<input type ="text" name = "subject" size ="90">
</td>
</tr>
<tr>
<td>
Content
</td>
<td>
<textarea name="content" cols="100" rows="10"></textarea>
</td>
</tr>
</table>
<div>
<input type = "submit" value = "저장">
</div>
</form>
<?php
include $_SERVER['DOCUMENT_ROOT'].'/footer.php';
?>
_最后这是我的DB现在的样子
_ +这是我的ap_bbs
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/preset.php';
?>
<?php
$reg_date = time();
$member_idx = $_SESSION['member_idx'];
$q = "INSERT INTO ap_bbs (member_idx, subject,content,reg_date) VALUES('$member_idx', '$subject', '$content', '$reg_date')";
$result = $mysqli->query($q);
if ($result==false) {
$_SESSION['writing_status'] = 'NO';
}
else {
$_SESSION['writing_status'] = 'YES';
}
$mysqli->close();
header('Location: '.$url['root'].'bbs/write_done.php');
exit();
?>