gpt4 book ai didi

php - 使用帖子变量更新日历中的现有事件

转载 作者:行者123 更新时间:2023-11-30 01:37:43 25 4
gpt4 key购买 nike

我被困在一个应该能够更新日历中现有事件信息的表单上。当通过表单从 event.php 页面传输数据到 event_updated.php 页面时,我无法让它识别它是从哪个事件发送的。 event_updated.php 页面应该识别这一点,更新数据库中的事件,然后使用新信息返回 event.php 页面。

这是 event.php 上的表单。 $id 变量是用于识别此页面上的事件的 GET 变量:

<form action="event_updated.php" method="post">
<p>Change name: <input type="text" name="event_name" value="'; if(isset($_POST['event_name'])) echo $_POST['event_name']; echo '" /><br />
New location: <input type="text" name="location" value="'; if(isset($_POST['location'])) echo $_POST['location']; echo '" /><br />
Starting (ex: 2013-05-01 18:00:00): <input type="text" name="starttime" value="'; if(isset($_POST['starttime'])) echo $_POST['starttime']; echo '" /><br />
Ending (ex: 2013-05-01 18:30:00): <input type="text" name="endtime" value="'; if(isset($_POST['endtime'])) echo $_POST['endtime']; echo '" /></p>
<input type="submit" value="Update event" />
<input type="hidden" name="this_event" value="'; $_POST['$id']; echo '" />
<input type="hidden" name="submitted" value="TRUE" />
</form>

这是来自 event_updated.php 的代码:

<?php
$page_title = "The event has been updated";

include ('../includes/topnavigation.php');
require_once ('../mysqli_connect.php');

session_start(); // Start session

// If no session value is set then they are redirected to index.php
if (!isset($_SESSION['user_id'])) {
require_once ('../includes/login_functions.inc.php');
$url = absolute_url();
header("Location: $url");
exit(); // Exit script
}

require_once ('../mysqli_connect.php'); // Connect to DB


//Check if the form has been submitted
if (isset($_POST['submitted'])) {

$errors = array(); //Initialize an error array

// Check for event name
if (empty($_POST['event_name'])) {
$errors[] = 'You have not given your event a name.';
} else {
$en = trim($_POST['event_name']);
}
// Check for event name
if (empty($_POST['this_event'])) {
$errors[] = 'this_event not transferred correctly.';
} else {
$en = trim($_POST['this_event']);
}
// Check for event location
if (empty($_POST['location'])) {
$errors[] = 'You have not determined where the meeting is taking place.';
} else {
$l = trim($_POST['location']);
}

if (empty($_POST['starttime'])) {
$errors[] = 'You have not determined when the meeting is starting.';
} else {
$s = trim($_POST['starttime']);

$s = strtotime($s);
$s = date('Y-m-d H:i:s',$s);
}
if (empty($_POST['endtime'])) {
$errors[] = 'You have not determined when the meeting is ending.';
}
else {
$e = trim($_POST['endtime']);

$e = strtotime($e);
$e = date('Y-m-d H:i:s',$e);
}

if (empty($errors)) { // If everything is ok

// Create the event in the database
require_once('../mysqli_connect.php'); // DB connect
$tbl_name="events";

$sql="UPDATE events SET creator_id='{$_SESSION['user_id']}',event_name=event_name, ,endtime=endtime,starttime=starttime,duration=duration,location=location WHERE this_event=event_id";
$result= @mysqli_query($dbc, $sql);

if($result){
// retrieve event from database
$user_id = $_SESSION['user_id'];
echo $user_id;
$event = "SELECT * FROM events e WHERE e.creator_id = {$_SESSION['user_id']} AND e.event_name = '$en'";
$r = @mysqli_query ($dbc, $event); // Run the query

if ($r) {
$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
$event_id = $row['event_id'];
echo $event_id;
header("Location: event.php?id=$event_id"); // $row['event_name']
} else {
echo mysqli_error($dbc);
}

echo "Succesfull";
echo "<BR>";
echo "<a href='newevent.php'>Back to main page</a>";
} else {
echo mysqli_error($dbc);
echo "ERROR";
echo $result;
echo '<h2>Error!</h2>
<p class="error">The following error(s) occured:<br />';
foreach ($errors as $msg) { // Print each error
echo " - $msg<br />\n";
}
}
mysqli_close($dbc);
}
else {
echo '<h2>Error!!!</h2>
<p class="error">The following error(s) occured:<br />';
foreach ($errors as $msg) { // Print each error
echo " - $msg<br />\n";
}
}
}
?>

event.php 的完整代码:

<?php

$page_title = 'View event';

include ('../includes/topnavigation.php');

session_start(); // Start session

// If no session value is set then they are redirected to index.php
if (!isset($_SESSION['user_id'])) {
require_once ('../includes/login_functions.inc.php');
$url = absolute_url();
header("Location: $url");
exit(); // Exit script
}

$id = $_GET['id'];
$loggedin = $_SESSION['user_id'];

require_once ('../mysqli_connect.php'); // Connect to DB

$event = "SELECT * FROM events e, users u WHERE u.user_id = e.creator_id AND e.event_id = $id";

$participants = "SELECT u.first_name, u.last_name FROM users u WHERE u.user_id IN (SELECT user FROM participants WHERE event = $id)";

$creator = "SELECT creator_id FROM events";

$add = "SELECT user_id as UserID, CONCAT(first_name, ' ', last_name) AS Name FROM users ORDER BY reg_date DESC";

$r = @mysqli_query ($dbc, $event); // Run the query

if ($r) { // If OK, display event

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

// Table with event info

echo '<h2>Event: ' . $row['event_name'] . '</h2>
<table>
<tr>
<td align="left" valign="top">
<table align="left" cellspacing="0" cellpadding="5">
<tr>
<td align="left">Date:</td><td align="left">' . $row['date'] . '</td>
</tr>
<tr>
<td align="left">Start:</td><td align="left">' . $row['starttime'] . '</td>
</tr>
<tr>
<td align="left">Duration:</td><td align="left">' . $row['duration'] . '</td>
</tr>
<tr>
<td align="left">Location:</td><td align="left">' . $row['location'] . '</td>
</tr>
<tr>
<td align="left">Creator:</td><td align="left"><a href="usermeetings.php?id='. $row['creator_id'] . '">' . $row['first_name'] . ' ' . $row['last_name'] . '</a></td>
</tr>';
}

mysqli_free_result ($r); // Free up the ressources

} else { // If failure

echo '<p class="error">Event info could not be retrieved. We apologize for any inconveniences.</p>';

// Debugging message:

echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $event . '</p>';

} // End of IF

$r = @mysqli_query ($dbc, $participants); // Run the query

if ($r) { // If OK, display event

echo '
<tr>
<td align="left">All participants:</td>
<td align="left">';
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo $row['first_name'] . ' ' . $row['last_name'] . '<br />';
}

mysqli_free_result ($r); // Free up the ressources

} else { // If failure

echo '<p class="error">Could not retrieve list of attending users. We apologize for any inconveniences.</p>';

// Debugging message:

echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $participants . '</p>';

} // End of IF

echo '
</td>
</tr>
</table>'; // Table is closed
echo '</td>
<td align="left" valign="top">';

$r = @mysqli_query ($dbc, $add);

if ($r) {

// Table header

echo '<h3>You have created this event</h3>
<p>Add participants, update info or simply delete it: <a href="deleteevent.php?id=' . $id .'">DELETE</a></p>

<p><b>Update event</b></p>

<form action="event_updated.php" method="post">
<p>Change name: <input type="text" name="event_name" value="'; if(isset($_POST['event_name'])) echo $_POST['event_name']; echo '" /><br />
New location: <input type="text" name="location" value="'; if(isset($_POST['location'])) echo $_POST['location']; echo '" /><br />
Starting (ex: 2013-05-01 18:00:00): <input type="text" name="starttime" value="'; if(isset($_POST['starttime'])) echo $_POST['starttime']; echo '" /><br />
Ending (ex: 2013-05-01 18:30:00): <input type="text" name="endtime" value="'; if(isset($_POST['endtime'])) echo $_POST['endtime']; echo '" /></p>
<input type="submit" value="Update event" />
<input type="hidden" name="this_event" value="'; if(isset($_POST['$id'])) echo $_POST['this_event']; echo '" />
<input type="hidden" name="submitted" value="TRUE" />
</form>

<table align="left" cellspacing="3" cellpading="3">

<tr>
<td align="left"><b>Add participants</b></td>
</tr>
';

// Fetch and print records:

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo '<tr>
<td align="left"><a href="usermeetings.php?id='. $row['UserID'] . '">' . $row['Name'] . '</td>
<td align="left"><a href="addparticipant.php?add='. $row['UserID'] . '&id=' . $id .'">ADD</a></td>
</tr>
';

}

echo '</table>'; // Table is closed

mysqli_free_result ($r); // Free up the ressources

} else { // If failure

echo '<br clear="all" /><p class="error">The user list could not be retrieved. We apologize for any inconveniences.</p>';

// Debugging message:

echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $add . '</p>';
}
echo '</td>
</tr>
</table>';

mysqli_close($dbc); // closes DB connection

?>

最佳答案

<input type="submit" value="Update event" name="submit"/>

if (isset($_POST['submitted'])) {

应该是

if (isset($_POST['submit'])) {

编辑1:还有

<form action="event_updated.php" method="post">
<p>Change name: <input type="text" name="event_name" value="<?php if(isset($_POST['event_name'])) echo $_POST['event_name'];?>" /><br />
New location: <input type="text" name="location" value="<?php if(isset($_POST['location'])) echo $_POST['location'];?>" /><br />
Starting (ex: 2013-05-01 18:00:00): <input type="text" name="starttime" value="<?php if(isset($_POST['starttime'])) echo $_POST['starttime'];?>" /><br />
Ending (ex: 2013-05-01 18:30:00): <input type="text" name="endtime" value="<?php if(isset($_POST['endtime'])) echo $_POST['endtime'];?>" /></p>
<input type="submit" value="Update event" />
<input type="hidden" name="this_event" value="<?php echo $_POST['$id'];>?" />
<input type="hidden" name="submitted" value="TRUE" />
</form>

关于php - 使用帖子变量更新日历中的现有事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16623119/

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