如何从另一个PHP页面创建并引入变量
我有一个在中创建的表 php。我将此页面称为事件。我在用户页面中使用了include函数来显示表,以便用户可以使用事件预订事件。问题是,我现在需要创建一个页面,一旦用户单击BookNow按钮,该页面就会运行。此页面将更新我的数据库中的预订表。我在这里完全迷路了,不知道如何创建这个页面,因为我想我需要一个从事件表引入的变量,可能是通过按钮。数据库中的预订表包含以下列。预订ID、用户ID、活动ID、付款类型和预订日期。我知道我正在使用mysql,但我会在这一切正常工作后得到更新的版本。我只是不知道从哪里开始创建预订PHP并将事件表中的值插入数据库。任何帮助都将不胜感激 这是显示在用户页面上的事件表,用于预订事件如何从另一个PHP页面创建并引入变量,php,mysql,html-table,Php,Mysql,Html Table,我有一个在中创建的表 php。我将此页面称为事件。我在用户页面中使用了include函数来显示表,以便用户可以使用事件预订事件。问题是,我现在需要创建一个页面,一旦用户单击BookNow按钮,该页面就会运行。此页面将更新我的数据库中的预订表。我在这里完全迷路了,不知道如何创建这个页面,因为我想我需要一个从事件表引入的变量,可能是通过按钮。数据库中的预订表包含以下列。预订ID、用户ID、活动ID、付款类型和预订日期。我知道我正在使用mysql,但我会在这一切正常工作后得到更新的版本。我只是不知道从
<?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);
?>
如果您要将数据发送到的页面位于同一主机上,则会话可能就是您要查找的内容。您还可以使用表单通过表单操作将数据发布到另一个页面以处理数据。如果数据不敏感,那么您可以使用GET甚至cookies在页面之间传递vars,但是传递数据似乎不是您主要关心的问题
要查看的一个选项是创建一个单独的页面来处理表单处理和插入数据,这可以在中调用
这听起来像你是新手,可能会使事情过于复杂,但值得一看。使用$\u SESSION
超级全局变量顺便说一句,不要使用太多的echo语句。您可以关闭php标记(?>)并编写普通html,然后在需要时再次打开它。否则,一个带有换行符的echo语句将非常有效。我正在使用会话,只是不在本页中,因为我只在另一页中包含它。感谢您的回复,我一定会看一看。我想我需要的是事件ID这里的echo“”$行['Event_ID']。""; 这样我就可以在预订页面上使用它将表中的数据插入到我的数据库中。