www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22

Thread: MySQLi problem when passing a variable as query

  1. #16
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    517
    Again - since I don't see any error checking code, how do you know it ran?

    When I run a query I always do:

    PHP Code:
    if ( !$results)
    {
        (
    show error messages)

    In development I send them to the screen. Once in prod they go to my error logs

    PS - It might be a good idea to not re-use your variable that holds the query statement to store your result object in. That way when you have an error you can display the query that you ran to help debug.

  2. #17
    Join Date
    Oct 2013
    Posts
    25
    Thanks for the reply!

    I used the code you provided and it just says:

    Code:
    Notice: Query returned 0 rows: SELECT * FROM `realtyimages` WHERE rname = 'Pacific Monarch Resorts' AND rcity = 'Las Vegas' AND rstate = 'NV'; in C:\xampp\htdocs\Auto Listing\database_class.php on line 32
    I was messing around with the sql query and found something odd. my query looks like this

    Code:
    $query = "SELECT * FROM `realtyimages` WHERE rname = '$rname' AND rcity = '$rcity' AND rstate = '$rstate' ";
    I tried to only use one WHERE clause like

    Code:
    $query = "SELECT * FROM `realtyimages` WHERE rname = '$rname'";
    Code:
    $query = "SELECT * FROM `realtyimages` WHERE rcity = '$rcity'";
    Code:
    $query = "SELECT * FROM `realtyimages` WHERE rstate = '$rstate' ";
    What i noticed is that rname has results, and rstate has results, but rcity is coming up with 0 rows. So i believe the problem is being caused my rcity. I am looking into it and will let you guys know.

  3. #18
    Join Date
    Oct 2013
    Posts
    25
    So I currently still facing this problem. From all the testing I have figure out that the Query is not liking when i give fcity a variable value. I echoed the query out and it works fine in my MySQL Client.

    What could cause this? It only is doing it to the fcity, not fname or fstate. Code works fine, rcity is defined and is correct, etc.

    I started a topic on stackoverflow if anyone is interested in looking there.

    http://stackoverflow.com/questions/2...01824_21412635

  4. #19
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    517
    Am I missing something? All along you have been referring to rcity rstate, etc. and today you post fcity and fstate.

    Is there a column named rcity?

  5. #20
    Join Date
    Oct 2013
    Posts
    25
    Quote Originally Posted by ginerjm View Post
    Am I missing something? All along you have been referring to rcity rstate, etc. and today you post fcity and fstate.

    Is there a column named rcity?
    Oops, that was a spelling error when I typed that reply. In the code and db columns, the names are rname, rcity, rstate.

  6. #21
    Join Date
    Oct 2013
    Posts
    25
    I think i found the problem, I feel pretty dump I overlooked something so simple. my $rcity which had the value "Las Vegas", when I var_dumped it, it showed it as string(10). Which Las Vegas should only have 9 characters including the space. Some reason it was adding another space, which was returning 0 results in the database. But to get even more odd, when I echoed out $rcity (with the added space) it looked normal, can't highlight the extra space and even was able to cut and paste it into phpmyadmin/mysqli client and it worked fine. So for some reason PHP was adding an extra character only between Las and Vegas.



    Thanks for all your help. Something so simple cause me all this problem. But hey I learned new ways to handle errors.

  7. #22
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,148
    Remember that web browsers remove duplicate word spaces when they format most HTML elements (with specific exceptions such as <pre> elements), so you may need to actually do a "view source" on the page to see the actual output. Or when outputting debug info, use <pre> tags. In fact, I have a macro in my editor that creates the following bit of PHP code:
    PHP Code:
    echo "<pre>".var_dump($data1)."</pre>"
    ...which saves me a lot of time. (The macro actually takes whatever is in the clipboard and inserts it where "$data" is.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles