1

I am trying to make a calendar to show the wash status of the cars of the specific days of the month. The days are assigned according to the package selected by the user. I am using Full Calendar for this purpose, but somehow my AJAX call returns nothing and I am stuck badly. Any help will be appreciated. All files and dependencies are properly linked.

Main FullCalendar CODE:

<script>
  $(function () {
    var zone = "08:00";
    var date = new Date();
    var d = date.getDate(),
        m = date.getMonth(),
        y = date.getFullYear();
    $('#calendar').fullCalendar({
      header: {
      },
      eventSources: [
        {
            url: 'process.php',
            type: 'POST',
            error: function() {
                alert('There was an error while fetching events.');
            }
        }
    ],
      editable: false,
      droppable: false,
    });
  });
</script>

and my Process.php code:

<?php
    include('db_connect.php');
    session_start();
    if(isset($_SESSION['userSession'])!=""){
        $user_id = $_SESSION['userSession'];
        $query = "select * from wash WHERE clientid='$user_id'";
        $res = mysql_query($query) or die(mysql_error());
        $events = array();
        while ($row = mysql_fetch_assoc($res)) {
            $wid = $row['wid'];
            $start = $row['wash_date'];
            if($row['wstatus'] == 0){
                $title = "Wash Scheduled";
                $backgroundColor = "#f39c12";
            }
            else if($row['wstatus'] == 1){
                $title = "Wash Done";
                $backgroundColor = "#00a65a";
            }

            $eventsArray['wid'] = $wid;
            $eventsArray['title'] = $title;
            $eventsArray['start'] = $start;
            $eventsArray['backgroundColor'] = $backgroundColor;
            $events[] = $eventsArray;
        }
        echo json_encode($events);
    }
?>

Kindly resolve.

  • [Little Bobby](http://bobby-tables.com/) says [your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard May 17 '16 at 19:05
  • Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 17 '16 at 19:05
  • Have you watched the AJAX request / response in the browser's developer tools? Have you included the jQuery library in the project? Are there any errors reported? Are you running this on a web-server? – Jay Blanchard May 17 '16 at 19:05
  • Yes I have included the JQuery library in my page. I am not displaying it on a web server currently, though I tried doing that as well, but no luck.! – Hussain Naqvi May 17 '16 at 19:12
  • AJAX requests will not run without a web-server. – Jay Blanchard May 17 '16 at 19:14
  • @JayBlanchard, sure brother. i will. its just a testing script. all things will be taken care of when finalizing for production. – Hussain Naqvi May 17 '16 at 19:18
  • I hate when people say *"I'm not that far along..."* or *"This site will not be public..."* or *"It's only for school, so security doesn't matter..."*. If teachers and professors are not talking about security from day one, they're doing it wrong. Challenge them. They're teaching sloppy and dangerous coding practices which students will have to unlearn later. I also hate it when folks say, *"I'll add security later..."* or *"Security isn't important now..."*. If you don't have time to do it right the first time, when will you find the time to add it later? ¯\\_(ツ)_/¯ – Jay Blanchard May 17 '16 at 19:19
  • ok ok jeez man, i got your point. I'll do that once I figure out whats the problem here in this snippet. Can you help here please @JayBlanchard?? – Hussain Naqvi May 17 '16 at 19:22
  • You said you were not running on a web-server. AJAX calls fail without them. You're overwriting the `$events` array on each loop. You're overwriting *all* of your variables on each loop. – Jay Blanchard May 17 '16 at 19:24
  • Fixed that, still no luck @JayBlanchard – Hussain Naqvi May 17 '16 at 19:39
  • Are you watching the AJAX request/response in the browser's console? – Jay Blanchard May 17 '16 at 19:54

0 Answers0