gpt4 book ai didi

php - 使用mysql编辑数据库中的数据时出错

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:06 25 4
gpt4 key购买 nike

这是我的代码,它显示当前事件并允许用户更改事件的日期、名称或地点。

出于某种原因,我不断收到 500 错误。我认为这是由于信息被传入和传出数据库。

数据库设置为:userid ,eventname, venue, date, name ,eventid... respectivley

        <div class="current events">
<h1>Your Current Events:</h1>
<?php

$sql = "SELECT * FROM events WHERE userid='{$_SESSION['u_id']}';";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)){
echo "<b>Event name: </b>";
echo " ";
echo $row['eventname'];
echo " ";
echo "<b>Event Venue: </b>";
echo " ";
echo $row['venue'];
echo " ";
echo "<b>Event Date: </b>";
echo " ";
echo $row['date'];
echo "
<form method='POST' action='editevent.php'>
<input type='hidden' name='eventname' value='" .$row['eventname']. "'>
<input type='hidden' name='venue' value='" .$row['venue']. "'>
<input type='hidden' name='date' value='" .$row['date']. "'>
<input type='hidden' name='name' value='" .$row['name']. "'>
<button>Edit</button>

</form>


";

}
}else{
echo "No Upcoming Events";
}

?>
</div>

然后我的 includes 目录中有另一个文件允许更改信息。

<?php

session_start();
if (isset($_POST['eventsubmit'])) {
$eventname = $_POST['eventname'];
$venue = $_POST['venue'];
$date = $_POST['date'];
$name = $_POST['name'];

$eventname = mysqli_real_escape_string($conn, $_POST['eventname']);
$venue = mysqli_real_escape_string($conn, $_POST['venue']);
$date = mysqli_real_escape_string($conn, $_POST['date']);
$name = mysqli_real_escape_string($conn, $_POST['name']);


$sql = "UPDATE events SET eventname='$eventname' WHERE userid='2' ";
mysqli_query($conn, $sql);
header("Location: ../members.php?event=success");
exit();



} else {
header("Location: ../signup.php");
exit();
}

}

最佳答案

我在第二个 php 文件中检查了你的代码,你多放了一个 请删除它。

关于php - 使用mysql编辑数据库中的数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46616961/

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