我正在尝试传递事件ID的值,因此当用户按下编辑按钮时,它会传递事件ID并编辑他们按下的特定事件。
数据库布局:userid,eventname,venue,date,name,eventid
尝试使用以下方法编辑数据库中的事件:
WHERE eventid='12' ";
通过id号码调用它,然后附加到eventid等于该数字的数据库
file:editevent.php:
<?php
include 'dbh.php';
include_once 'header.php';
session_start();
if(!isset($_SESSION['u_uid'])){
header("Location:signup.php");
}
?>
<section class="main-container">
<h1>test</h1>
<?php
$eventname = mysqli_real_escape_string($conn, $_POST['eventname']);
$venue = mysqli_real_escape_string($conn, $_POST['venue']); //last
$date = mysqli_real_escape_string($conn, $_POST['date']); //email
$name = mysqli_real_escape_string($conn, $_POST['name']); //uid
echo "<form method='POST' action='includes/editevents.inc.php'>
<input type ='text' name='eventname' placeholder='event name'>
<input type ='text' name='venue' placeholder='event name'>
<input type ='date' name='date' placeholder='event date'>
<button type='submit' name='eventsubmit'>Submit</button>
</form>";
?>
</section>
file:editevents.inc.php:
<?php
include 'dbh.inc.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 eventid='12' ";
mysqli_query($conn, $sql);
header("Location: ../members.php?event=success");
exit();
} else {
header("Location: ../signup.php");
exit();
}
答案 0 :(得分:0)
您还需要在html表单中添加eventid
<input type ='text' name='eventname' placeholder='event name'>
<input type ='text' name='venue' placeholder='event name'>
<input type ='date' name='date' placeholder='event date'>
<!-----Include event id of the event you want to update ---->
<input type ='hidden' name='eventid' value="$eventid">
<button type='submit' name='eventsubmit'>Submit</button>
所以这也会被提交,你可以像这样得到它
<?php
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']);
$eventid =mysqli_real_escape_string($conn, $_POST['eventid']);
$sql = "UPDATE events SET eventname='$eventname' WHERE eventid='$eventid' ";