通过PHP中的表填充数据库

时间:2014-01-13 15:15:50

标签: php mysql sql database

我正在开发一个简单的小型预订系统,因为我是PHP新手。我有一个通过表填充数据库的问题。管理员可以创建事件,然后由用户预订。我很肯定我离开了预订活动,但我不确定。我希望有人可以通过提供一些我出错的例子来帮助我,以及如果我以用户身份登录,我可以做些什么来实际预订活动。我将提供代码和表格的图像。如果您需要更多页面,请告诉我,我会发布它们。

表格图片

the table that the user can use to book an event

事件表

<?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' name='submit'     eventid=' .row['Event_ID'] .' value='Book now'></td>";
    echo "</tr>";
    echo "</form>";
    echo "</tbody>";
}

mysql_close($con);
?>

到目前为止,我在预订时所拥有的内容

<?php
session_start();

$con = mysql_connect("localhost","root","");

if(!$con)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("flexiflash", $con);

$date = date('Y-m-d H:i:s');
//$card = ($_POST['P_card']);
//$paypal = ($_POST['P_paypal']);

$event_id = $row['Event_ID'];

$_SESSION['user_id'];

$insert = mysql_query("INSERT INTO booking (User_ID,Event_ID,Date_Booked) VALUES ('". $_SESSION['userid'] . ",". $event_id .","$date"')");

$row = mysql_query("SELECT * FROM events");

mysql_close($con);
?>

0 个答案:

没有答案