3

Please don't ask why I use mysql_* functions. I just need to use this for now so please don't suggest mysqli_* functions and PDO cause i'm aware of that.
My problem is that my query doesn't return any data. But when I tried to run the sql in my server it worked so I just don't know what I'm missing right now. So please help.
Here is my script:

   $(document).on('click','#btn-generate-pdf',function(){
        var date = $('#service-date').val(),
            dataString = "date="+ date;
            $.ajax({
                type: "POST",
                url: "functionko.php?call=retrievedate",
                data: dataString,
                success:function(data){
                    $('#services-container').html(data);
                }
            });         
    });

And here is my functionko.php

   switch($_GET['call']){   
  case 'test':
    checkuser();
     break;
  case 'getuser';
    getuser();  
    break;
  case 'paybill';
    paybill();
    break;
  case 'retrievedate';
    retrievedate(); //<-----
    break;  
  default:
    break;
 }

    function retrievedate(){
    $date = '2013-12-19';
    //$date = $_POST['date'];
    $sql = "SELECT * FROM rendered_services WHERE rendered_date = '$date'";
    $result = mysql_query($sql);
    $data= array();
    print_r($sql);
    if($result){
        while($row = mysql_fetch_assoc($result)){
            echo $row['client_name'];
        }
    }else{
        echo '
        <table border="0"  width="100%" cellpadding="0" cellspacing="0"  class="display" id="attendance" class="jtable" >       
            <thead>
                <tr>
                    <th>Client Name</th>
                    <th>Service Name</th>                       
                    <th>Date</th>
                    <th>Therapist</th>
                    <th>Status</th>
                    <th>Price</th>
                    <th>Subtotal</th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>';
    }

So what I'm missing here? TIA!

14
  • what you got when you run print_r ? Commented Dec 19, 2013 at 4:42
  • SELECT * FROM rendered_services WHERE rendered_date = '2013-12-19' I got this and when I try to run it in my server it worked! Commented Dec 19, 2013 at 4:44
  • Try putting switch($_GET['call']){...} after your retrievedate() function. Commented Dec 19, 2013 at 4:46
  • @Fred-ii- I'm sorry? What does the structure will look like? Commented Dec 19, 2013 at 4:50
  • 1
    Assuming the else portion of your retrievedate() function still runs on ajax post, it seems this would point to a connection issue. Commented Dec 19, 2013 at 4:55

2 Answers 2

2

You are making ajax post from your client. But in functionko.php file, you are processing it as GET.

 switch($_GET['call']){   

should be

switch($_POST['call']){  

I would suggest you change the ajax request type from POST to GET and check if its working fine.

Sign up to request clarification or add additional context in comments.

1 Comment

@leonardeveloper: comment out the switch condition and trigger retrievedate() and check if you are getting any result. Your page doesnt have any dependency on the POSTED values.
0

variable in single quote is not evaluated. So the $date is note replaced with its value in the following string.

$sql = "SELECT * FROM rendered_services WHERE rendered_date = '$date'";

Following modification will work:

    $sql = "SELECT * FROM rendered_services WHERE rendered_date = '".$date."'";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.