Jump to content

Php/Javascript problems, Have no knowlege of AJAX, can someone please guide me in the right direction


dave_Ireland

Recommended Posts

 

 

Hi guys,

 

I was wondering if i could have some help on a piece of functionality I am trying to implement onto a website I am currently developing.

 

The Scenario is as follows :

 

I have a table residing on a MySql data base called Bookings.  

The Bookings table consists of a composite primary key based upon the following 2 fields: BookingDate & Booking Slot.

 

On my website, I have built a bookings page which will consist of a a simple HTML Form, which has a Date Field and a Radio-Button group which has 3 different time slots (eg: 9am, 2pm and 4pm).

Firstly, the User will select a Date they would wish to place a booking on and then click a submit button called "Check Availablity".

Once this button is clicked, Ideally, I would like a script to check an see what free slots are available for that Date and then disable the radio buttons related the slots which are already booked.

 

Here is a simple scenario to help explain the functionality i am trying to implement :

 

The User comes to the Bookings page, and selects the Date 14/03/2011. Then clicks the "Check Availablity" button.

In this scenario, the 9am slot is already booked for this date (eg: this booking already exists on the MySql database table), 

so the 9am radio button on the page is then disabled, not allowing the user to try an attempt to book this timeslot on this date.

 

Below is the a simplified version of the php script which I wrote to implement the this functionality.

 

 

<?php

function checkSlot()

{

 

  // Get data 

$test_date = $_GET["bookingDate"]; 

 

// Database connection 

$conn = mysqli_connect("localhost","root","","wordpress"); 

if(!$conn) { 

die('Problem in database connection: ' . mysql_error()); 

 

// Attempt to find Duplicate Primary Keys

 

$query = "SELECT Count(*) AS 'total' FROM Bookings WHERE booking_date ='{$booking_date}' AND booking_slot = '9am'";

 

$result = mysqli_query($conn, $query) or die(mysqli_error($conn)); 

 

$num = $result->fetch_assoc(); 

 

 If ($num['total'] == 0) 

 {

    echo "<script> document.getElementById('9amTimeSlotRadioButton').disabled  = false; </script>";

 

 }

 else if($num['total'] > 0)

 {

   echo "<script> document.getElementById('9amTimeSlotRadioButton').disabled  = true; </script>";

 }

}

?>

 

My problem is that I cant get the Javascript line within the if statement to execute and disable/enable the related 9am radio button.

 

Upon research into this, I have recently found out that it is not possible to do this with just Php and JavaScript, as php runs serverside and javascript runs client-side and Ajax would be needed here.

 

So, im in a spot of bother now as one of the main selling points of this project was to be able to get this functionality working.

 

I have a massive favour to ask of you guys, could you chime in and guide me on how to implement this functionality by using Ajax?

 

I have zero experience in the language so I really dont know where to start.

 

Any input at all on this topic would be much appreciated.

 

Thanks in advance guys,

 

Dave

Ireland.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.