Hi guys

Need help with my php booking form code....
basically when the customer selects a particular activity the database checks for the value assigned to that activity
for example in my database
ive assigned football and basketball with the value of 4
badmington, tennis and table tennis with the value of 1
and half basketball with the value of 2
the value represents the space each activity will take up.
after it checks the value it then checks the hall number, start time, end time and date to see if the room is free. if the room or hall is free then the customer can continue to book if not it should bring up an error.

now i dnt know if iv used the switch case correctly nor does the code work... am i missing something or??

<?php
include("connect.inc.php");

$Activity=mysql_real_escape_string($_POST['Activity']);
$Date=mysql_real_escape_string($_POST['Date']);
$Start_Time=mysql_real_escape_string($_POST['Start_Time']);
$End_Time=mysql_real_escape_string($_POST['End_Time']);
$HallNumber=mysql_real_escape_string($_POST['HallNumber']);
$Equipment=mysql_real_escape_string($_POST['Equipment']);
$CustomerID=mysql_real_escape_string($_POST['CustomerID']);
$ActivityID=mysql_real_escape_string($_POST['ActivityID']);
$EquipmentID=mysql_real_escape_string($_POST['EquipmentID']);
$Firstname=mysql_real_escape_string($_POST['Firstname']);
$Lastname=mysql_real_escape_string($_POST['Lastname']);

//when selecting the activity from the booking form
// the code below checks the value of that activity
//
$select = "SELECT Value FROM Activity WHERE Activity_Type = '$Activity'";
$pick = mysql_num_rows($select);

if ($pick) {

    case 8:
        if ($pick >=8)
            echo "Sorry Cannot Book"
    break;

    case 4:
            if($pick != 4)
    break;

    case 2:
            if($pick != 2)
    break;

    case 1:
            if($pick != 1)
    break;

    default:
            die (mysql_error());
    break;
    # code...
}
$checkActivity = "SELECT Activity_ID FROM Activity WHERE Activity_Type ='$Activity'";
$act = mysql_query($checkActivity);
    if($act)
    {
        $row_get = mysql_fetch_array($act);
        $activity_id = $row_get['Activity_ID'];
    }
    else
    {
        die (mysql_error());    
    }
$check = "SELECT Equipment_ID FROM Equipment WHERE Equipment_Type = '$Equipment'";
$set = mysql_query($check);
    if($set)
    {
        $row_get = mysql_fetch_array($set);
        $equipment_id = $row_get['Activity_ID'];
    }
    else
    {
        die (mysql_error());
    }
$client = "SELECT Customer_ID FROM Customer WHERE FName = '$Firstname' AND SName = '$Lastname'";
$find = mysql_query($client);
    if($find){
        $row_get = mysql_fetch_array($find);
        $customer_id = $row_get['Customer_ID'];
    }
    else
    {
        die (mysql_error());
    }

// checks if the hall, start and end time and date of a particular room is free or has been booked
$result = mysql_query("SELECT * FROM Booking WHERE Hall_Number =$HallNumber AND Start_Time =  '$Start_Time' AND End_Time =  '$End_Time' AND DATE =  '$Date' LIMIT 1");

if( mysql_num_rows($result) > 0) {
     // room is not booked
    echo "Unfortunately the room has been booked";
}
else
{ mysql_query("INSERT Booking (ID, Activity_Type, Date, Start_Time, End_Time, Hall_Number, fk1_Customer_ID, fk1_Activity_ID, fk1_Equipment_ID)
     VALUES (NULL, $Activity, $Date, $Start_Time, $End_Time, $Hall_Number, $customer_id, $activity_id, $equipment_id)");
    // room is booked
}

?>

Recommended Answers

All 4 Replies

Member Avatar for diafol

This code is riddled with deprecated functions: mysql_* Use PDO or mysqli.

The switch block is weird. It doesn't make any sense.

Can't use mysqli as the current phpmyadmin am using is the older version

also i dont know how to use the switch case function hence would appreciate if someone could like give me an example of how its used.

Can't use mysqli as the current phpmyadmin am using is the older version

The MySQLi extension and PhpMyAdmin are unrelated.

i dont know how to use the switch case function

switch ($pick) 
{
    case 8:
        // your code when $pick is 8
        break;

    case 4:
        // your code when $pick is 4
        break;

    case 2:
        // your code when $pick is 2
        break;

    case 1:
        // your code when $pick is 1
        break;

    default:
        // // your code when $pick is any other value
        break;
}

Thanks guys for your help.. iv managed to get the booking form working

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.