gpt4 book ai didi

php - 用户 ID 进入数据库,而不是通过电子邮件发送

转载 作者:行者123 更新时间:2023-11-29 10:29:11 24 4
gpt4 key购买 nike

无论如何,我已经尝试了几个小时,这个表单假设要获取正在显示的我的电子邮件,并在提交时将包括电子邮件在内的详细信息插入到数据库中。 Form

它不是获取我的“电子邮件”,而是从用户表中获取我的用户 ID(自动增量)并将其更新到反馈表中。 database

反馈.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>

最佳答案

通过使用建议修复了这个问题,因为登录页面本身的 ID 和电子邮件之间的登录 session 是混合的。

<?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>

关于php - 用户 ID 进入数据库,而不是通过电子邮件发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47737384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com