一直在尝试几个小时无论如何这个表格假设我的电子邮件正在显示并在提交时插入详细信息包括电子邮件到数据库。
不是取我的'电子邮件'而是从用户表中获取用户ID(自动增量)并将其更新到反馈表中。
feedback.php
<?php
$email =(isset($_SESSION['email']) ? $_SESSION['email'] : null);
$name='';$feedback=''; $topic=''; $details='';
$action =(isset($_POST['submit']) ? $_POST['submit'] : null);
if($action!=null) {
$name =(isset($_POST['name']) ? $_POST['name'] : null);
$feedback =(isset($_POST['feedback']) ? $_POST['feedback'] : null);
$topic =(isset($_POST['topic']) ? $_POST['topic'] : null);
$details =(isset($_POST['details']) ? $_POST['details'] : null)
if($details==null) {
echo "<br><p style='text-align:center;color:red'>Please fill up all text fields!</p>";
}
else {
$query="insert into feedback values('','$email','$name','$feedback','$topic','$details','',null)";
$result=mysql_query($query);
echo "<br><p style='text-align:center;color:blue'>Successfully submit the feedback to system </p>";
$feedback=''; $topic=''; $details='';
}
if( mysql_error()!="") {
echo "<font style='text-align:center;color:red'>" . mysql_error() . "</font><br>";
}
}
?>
<form method="post" action="user_feedback.php">
<?php
$email =(isset($_SESSION['email']) ? $_SESSION['email'] : null);
$query="select * from user where id=$email";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
?>
<br>
<table cellpadding="5">
<tr><td style="width:150px">User Email</td><td><input type="text" name="email" value="<?php echo $row['email'] ?>" disabled style="width:200px;" ></td></tr>
<tr><td>User Name</td><td><input type="text" name="name" value="<?php echo $name ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback</td>
<td>
<select name="feedback" style="height:32px">
<option <?php if($feedback=="Inquiry") { echo 'selected'; } ?> >Inquiry</option>
</select>
</td>
</tr>
<tr><td>Feedback Topic</td><td><input type="text" name="topic" value="<?php echo $topic ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback Details</td><td><textarea type="comment" name="details" value="<?php echo $details ?>" style="width:500px;" ></textarea></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Submit" class="tall"></td></tr>
</table>
</form>
答案 0 :(得分:1)
通过使用建议来修复它,因为登录页面上的id和电子邮件之间存在登录会话的混淆。
<?php
//echo("{$_SESSION['id']}"."<br />");
$email =(isset($_SESSION['id']) ? $_SESSION['id'] : null);
$name='';$feedback=''; $topic=''; $details='';
$action =(isset($_POST['submit']) ? $_POST['submit'] : null);
if($action!=null) {
$name =(isset($_POST['name']) ? $_POST['name'] : null);
$feedback =(isset($_POST['feedback']) ? $_POST['feedback'] : null);
$topic =(isset($_POST['topic']) ? $_POST['topic'] : null);
$details =(isset($_POST['details']) ? $_POST['details'] : null);
if($topic==null || $details==null) {
echo "<br><p style='text-align:center;color:red'>Please fill up all text fields!</p>";
}
else {
$query="insert into feedback values('','$email','$name','$feedback','$topic','$details','',null)";
$result=mysql_query($query);
echo "<br><p style='text-align:center;color:blue'>Successfully submit the feedback to system </p>";
$feedback=''; $topic=''; $details='';
}
if( mysql_error()!="") {
echo "<font style='text-align:center;color:red'>" . mysql_error() . "</font><br>";
}
}
?>
<form method="post" action="user_feedback.php">
<?php
$email =(isset($_SESSION['email']) ? $_SESSION['email'] : null);
$query="select * from user where id=$email";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
?>
<br>
<table cellpadding="5">
<tr><td style="width:150px">User Email</td><td><input type="text" name="email" value="<?php echo $row['email'] ?>" disabled style="width:200px;" ></td></tr>
<tr><td>User Name</td><td><input type="text" name="name" value="<?php echo $name ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback</td>
<td>
<select name="feedback" style="height:32px">
<option <?php if($feedback=="Inquiry") { echo 'selected'; } ?> >Inquiry</option>
</select>
</td>
</tr>
<tr><td>Feedback Topic</td><td><input type="text" name="topic" value="<?php echo $topic ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback Details</td><td><textarea type="comment" name="details" value="<?php echo $details ?>" style="width:500px;" ></textarea></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Submit" class="tall"></td></tr>
</table>
</form>