[英]In PHP, How would I use a variable that was created in another php page?
[英]How would I create and bring in a variable from another PHP page
我有一个在php中创建的表。 我称此为页面事件。 我在用户页面中使用了include函数来显示表,以便用户可以使用事件来预订事件。 关键是,我现在需要创建一个页面,该页面将在用户单击“立即预订”按钮后立即运行。 该页面将更新我数据库中的预订表。 我在这里完全迷失了方向,不知道如何创建该页面,因为我认为我需要从事件表(可能是通过按钮)中引入的变量。 数据库中的预订表具有这些列。 预订ID,用户ID,事件ID,付款类型和预订日期。 我知道我使用的是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个月,所以我知道这不是最好的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.