【发布时间】:2018-06-05 01:56:13
【问题描述】:
我有一个创建于 php。我已将此页面称为事件。我在我的用户页面中使用了一个包含函数来显示表格,以便用户可以使用这些事件来预订一个事件。问题是,我现在需要创建一个页面,该页面将在用户单击“立即预订”按钮后运行。此页面将更新我数据库中的预订表。我在这里完全迷失了,不知道如何创建这个页面,因为我认为我需要一个从事件表中引入的变量,也许是通过按钮。数据库中的预订表有这些列。 Booking_ID、User_ID、Event_ID、Payment_Type 和 Date_Booked。我知道我正在使用 mysql,但是在我完成所有工作后我会得到更新的版本。我只是不知道从哪里开始创建预订 PHP 并将事件表中的值插入数据库。任何帮助将不胜感激。
这是在用户页面上显示的用于预订活动的活动表
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("flexiflash", $con);
// Creating the foundations for the table headings //
echo "<thead>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Venue</th>";
echo "<th>Event</th>";
echo "<th>Date</th>";
echo "<th>Time</th>";
echo "<th></th>";
echo "</tr>";
echo "</thead>";
// Running a JavaScript function to check for the user's payment type before submitting the form to book_event.php //
echo '<script>
function check() {
if (document.getElementById("checkbox").checked && document.getElementById("card").checked)
{
alert("Pay by card with 20% off");
return true;
}
else if (document.getElementById("checkbox").checked && document.getElementById("paypal").checked)
{
alert("Pay via PayPal with 20% off");
return true;
}
else if (document.getElementById("card").checked)
{
alert("Pay by card without a voucher!");
return true;
}
else if (document.getElementById("paypal").checked)
{
alert("Pay via PayPal without a voucher!");
return true;
}
else
{
alert("Nothing was checked. Please select your payment type");
return false;
}
}
</script>';
$result = mysql_query("SELECT * FROM events");
while($row = mysql_fetch_array($result))
{
// Outputting the data from the $result variable into a formatted table //
echo "<tbody>";
echo "<form class='table-form' action='book_event.php' method='post' onsubmit='return check()'>";
echo "<tr>";
echo "<td>" . $row['Event_ID'] . "</td>";
echo "<td>" . $row['Event_Venue'] . "</td>";
echo "<td>" . $row['Event_Name'] . "</td>";
echo "<td>" . $row['Event_Date'] . "</td>";
echo "<td>" . $row['Event_Time'] . "</td>";
echo "<td><input type='submit' class='sub_btn' value='Book now'></td>";
echo "</tr>";
echo "</form>";
echo "</tbody>";
}
mysql_close($con);
?>
如果您需要更多代码或任何其他信息,请随时询问。
我知道我的代码不是很好,我在我的 PHP 中使用 Javascript,但我仍在学习 PHP。只做了大约 2 个月,所以我知道它不是最好的。
【问题讨论】:
-
使用
$_SESSION超级全局变量 -
顺便说一句,不要使用这么多的 echo 语句。您可以关闭 php 标签 (?>) 并编写普通的 html,然后在需要时再次打开它。否则,一个带有换行符的 echo 语句将完美运行。
-
我正在使用会话,只是不在此页面中,因为我仅将其包含在另一个页面中。
标签: php mysql html-table