Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Why is nothing returned from SQLite DB? (PHP)

  1. #1
    Join Date
    May 2011
    Beans
    253
    Distro
    Ubuntu 12.04 Precise Pangolin

    Why is nothing returned from SQLite DB? (PHP)

    When I run the follwing via a php file
    Code:
    $query = "SELECT * FROM lead_info
                    ORDER BY ROWID DESC LIMIT 1";
     
    $result = sqlite_query($query, $db) or die("Retrieve Query Failed");
    $row = sqlite_fetch_array($result);
    print("ID: " . $row['rowid'] . "<br />");
    print("Name: " . $row['name'] . "<br />");
    print("E-mail: " . $row['email'] . "<br />");
    print("Phone: " . $row['phone'] . "<br />");
    print("Phone Type: " . $row['phonetype'] . "<br />");
    print("Country: " . $row['country'] . "<br />");
    print("Date: " . $row['date'] . "<br />");
    print("Comment: " . $row['comment'] . "<br />");
    nothing prints out on the webpage. Printing $result give me a blank ObjectID.

    I've tested the query and that works.
    Using PHP4 and SQLite3 on Monkey web-server (hosted on Damn Small Linux).
    Kevin Harper
    http://www.kevinharper.com/


    Ubuntu: Because rebooting is ONLY for installing hardware

  2. #2
    Join Date
    May 2006
    Beans
    1,787

    Re: Why is nothing returned from SQLite DB? (PHP)

    Quote Originally Posted by kevinharper View Post
    When I run the follwing via a php file
    Code:
    $query = "SELECT * FROM lead_info
                    ORDER BY ROWID DESC LIMIT 1";
     
    $result = sqlite_query($query, $db) or die("Retrieve Query Failed");
    $row = sqlite_fetch_array($result);
    print("ID: " . $row['rowid'] . "<br />");
    print("Name: " . $row['name'] . "<br />");
    print("E-mail: " . $row['email'] . "<br />");
    print("Phone: " . $row['phone'] . "<br />");
    print("Phone Type: " . $row['phonetype'] . "<br />");
    print("Country: " . $row['country'] . "<br />");
    print("Date: " . $row['date'] . "<br />");
    print("Comment: " . $row['comment'] . "<br />");
    nothing prints out on the webpage. Printing $result give me a blank ObjectID.

    I've tested the query and that works.
    Using PHP4 and SQLite3 on Monkey web-server (hosted on Damn Small Linux).
    What happens if you run the code in a terminal window?

  3. #3
    Join Date
    May 2011
    Beans
    253
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Why is nothing returned from SQLite DB? (PHP)

    that's what I meant by tested the query...

    I ssh'd to server
    $sqlite leads
    >SELECT * FROM lead_info ORDER BY ROWID DESC LIMIT 1;

    It works. I get the row w/ the highest ROWID - the last record entered.

    EDIT: This is the second query of the script. The first also uses $query and $results. I thought it may be a problem. So, JUST NOW, I changed vars to $query2 and $results2. Made no difference.
    Last edited by kevinharper; November 2nd, 2011 at 10:26 PM.
    Kevin Harper
    http://www.kevinharper.com/


    Ubuntu: Because rebooting is ONLY for installing hardware

  4. #4
    Join Date
    Nov 2009
    Beans
    1,081

    Re: Why is nothing returned from SQLite DB? (PHP)

    http://php.net/manual/en/function.sq...etch-array.php

    Judging from that, I have to wonder whether you swapped the order of the database handle and the query.

  5. #5
    Join Date
    May 2011
    Beans
    253
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Why is nothing returned from SQLite DB? (PHP)

    Yeah.. I thought that also at one point. But if there is no second argument, it defaults to SQLITE_BOTH... I have also explicitly indicated SQLITE_BOTH & SQLITE_ASSOC (in separate tries) and nothing.

    Is that what you were referring to?
    Kevin Harper
    http://www.kevinharper.com/


    Ubuntu: Because rebooting is ONLY for installing hardware

  6. #6
    Join Date
    May 2011
    Beans
    253
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Why is nothing returned from SQLite DB? (PHP)

    @Arndt is this:
    Quote Originally Posted by kevinharper View Post
    I ssh'd to server
    $sqlite leads
    >SELECT * FROM lead_info ORDER BY ROWID DESC LIMIT 1;

    It works. I get the row w/ the highest ROWID - the last record entered.
    Is this what you meant by "run the code in a terminal"?
    Kevin Harper
    http://www.kevinharper.com/


    Ubuntu: Because rebooting is ONLY for installing hardware

  7. #7
    Join Date
    May 2011
    Beans
    253
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Why is nothing returned from SQLite DB? (PHP)

    Here's the whole thing:
    Code:
          1 <?
          2 // Inserts lead info into lead_info table. Info coming from add_new_lead        .php
          3 
          4 include_once "header.php";
          5 
          6 $month = $_POST['month'];
          7 $day   = $_POST['day'];
          8 $year  = $_POST['year'];
          9 $date  = $year . "-" . $month . "-" . $day;
         10 
         11 $name  = $_POST['name'];
         12 $email = $_POST['email'];
         13 $phone = $_POST['phone'];
         14 $phonetype = $_POST['phonetype'];
         15 $country = $_POST['country'];
         16 $comment = $_POST['comment'];
         17 
         18 /*print("Date: " . $month . "/" . $day . "/" . $year . "<br />");
         19 print("Name: " . $name . "<br />");
         20 print("E-mail: " . $email . "<br />");
         21 print("Phone: " . $phone . "<br />");
         22 print("Country: " . $country . "<br />");
         23 print("Phone Type: " . $phonetype . "<br />");
         24 print("Comments: <br />" . $comment);*/
         25 
         26 // INSERT LEAD INFORMATION
         27 $query = "INSERT INTO lead_info(name,email,phone,phonetype,country,date,        comment)
         28                 VALUES('" . $name               . "'," .
         29                         "'" . $email            . "'," .
         30                         "'" . $phone            . "'," .
         31                         "'" . $phonetype        . "'," .
         32                         "'" . $country          . "'," .
         33                         "'" . $date             . "'," .
         34                         "'" . $comment          . "')";
         35 
         36 sqlite_query($query, $db) or die("Query Failed");
         37 
         38 // RETRIEVE INFO FROM LAST ENTRY
         39 $query = "SELECT * FROM lead_info
         40                 ORDER BY ROWID DESC LIMIT 1";
         41 
         42 $result = sqlite_query($query, $db) or die("Retrieve Query Failed");
         43 $row = sqlite_fetch_array($result);
         44 print("ID: " . $row['rowid'] . "<br />");
         45 print("Name: " . $row['name'] . "<br />");
         46 print("E-mail: " . $row['email'] . "<br />");
         47 print("Phone: " . $row['phone'] . "<br />");
         48 print("Phone Type: " . $row['phonetype'] . "<br />");
         49 print("Country: " . $row['country'] . "<br />");
         50 print("Date: " . $row['date'] . "<br />");
         51 print("Comment: " . $row['comment'] . "<br />");
         52 
         53 include_once "footer.php";
         54 ?>
    The script gets info from an HTML form.

    The first query... the one that inserts data works fine. The server times out often when submitting the form but that's just the computer this is all running on. I simply go back and resubmit the info. But when it goes through, the data is inserted into the table but nothing is retrieved.

    Hope this helps in providing additional cues as to what is going on. I've used mySQL quite a bit but this is my first time with SQLite. But it doesn't seem like I should be having this problem.
    Kevin Harper
    http://www.kevinharper.com/


    Ubuntu: Because rebooting is ONLY for installing hardware

  8. #8
    Join Date
    May 2011
    Beans
    253
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Why is nothing returned from SQLite DB? (PHP)

    This may help...

    I added
    Code:
         43 if($result)
         44         print('$result is blank');
    And it prints out "$result is blank" on the web page. So it looks like the query is executing, otherwise it would die & err w/ "Retrieve Query Failed", right?

    To me, at least, it looks like nothing is being assigned to $result.
    Kevin Harper
    http://www.kevinharper.com/


    Ubuntu: Because rebooting is ONLY for installing hardware

  9. #9
    Join Date
    May 2006
    Beans
    1,787

    Re: Why is nothing returned from SQLite DB? (PHP)

    Quote Originally Posted by kevinharper View Post
    @Arndt is this:

    Is this what you meant by "run the code in a terminal"?
    No, I meant run the php code.

  10. #10
    Join Date
    May 2011
    Beans
    253
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Why is nothing returned from SQLite DB? (PHP)

    I commented out the everything related to inserting data and ran. So it should have simply returned the last row.

    From SQLite, this is what I get (and what I am expecting to get):

    EDIT: The following columns are messed up on the page, but the first row is a header, not results.

    sqlite> SELECT * FROM lead_info ORDER BY ROWID DESC LIMIT 1;
    name email phone phonetype country date comment
    ---------- ---------- ---------- ---------- ---------- ---------- ---------------
    fritest email phone home country 2011-01-01 1st Friday test

    I commented everything out from the script except for what is essential for the SELECT statement. Here is what was left:
    Code:
    1 <?
    
    5 include_once "db_config.php";
    
    42 // RETRIEVE INFO FROM LAST ENTRY
    43 $query = "SELECT * FROM lead_info
    44                 ORDER BY ROWID DESC";
    45 
    46 $result = sqlite_query($query, $db) or die("Retrieve Query Failed");
    47 print('$result: ' . $result);
    48 
    49 $row = sqlite_fetch_array($result);
    50 print("ID: " . $row['rowid'] . "<br />");
    51 print("Name: " . $row['name'] . "<br />");
    52 print("E-mail: " . $row['email'] . "<br />");
    53 print("Phone: " . $row['phone'] . "<br />");
    54 print("Phone Type: " . $row['phonetype'] . "<br />");
    55 print("Country: " . $row['country'] . "<br />");
    56 print("Date: " . $row['date'] . "<br />");
    57 print("Comment: " . $row['comment'] . "<br />");
    
    60 ?>
    I ran it as:
    dsl@0[bin]$ vim ../../monkey-0.9.2/htdocs/insert_lead.php.php

    And got:
    Content-type: text/html
    X-Powered-By: PHP/4.3.7

    $result: ObjectID: <br />Name: <br />E-mail: <br />Phone: <br />Phone Type: <br />Country: <br />Date: <br />Comment: <br />

    So, exactly the same result.
    Kevin Harper
    http://www.kevinharper.com/


    Ubuntu: Because rebooting is ONLY for installing hardware

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •