a php code works fine in local host on my computer but not work on server

Discussion in 'PHP' started by hope2life, Aug 11, 2012.

  1. #1
    Hi,


    $query="SELECT * FROM products WHERE cat1='$cat1' AND cat2='$cat2' AND cat3 IS NULL Limit ".$x.",".$y;

    cat3 is null work well on local host on computer and return rows from table in database
    but it doesnt work on my web hosting server and doesnt return any rows

    Can anyone help with this?
     
    Last edited: Aug 11, 2012
    hope2life, Aug 11, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    You probably have no rows in which cat3 is null. (Blank and null are different. Null means that nothing has ever been written to that field on that row. Storing '' to the field leaves it blank, not null.) If you saved your data locally, then inserted it into the database on the server - and the insert statement included inserting cat3 as '' - there are no rows in which cat3 is null. Try

    WHERE cat1='$cat1' AND cat2='$cat2' AND cat3 = '' Limit ".$x.",".$y;

    (That's 2 single quotes.)
     
    Rukbat, Aug 11, 2012 IP
  3. hope2life

    hope2life Active Member

    Messages:
    1,641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    90
    #3
    i think it was a browser cache problem. The script which was not working yesterday, working absolutely fine today after I closed the browser last night. I should have deleted cookies and temporary internet files.


    Rukbat can you please tell me how can I replace '' to null in fields in existing table in database?
     
    hope2life, Aug 11, 2012 IP
  4. sources68

    sources68 Member

    Messages:
    74
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #4
    you can change field cat3 default null and replace '' to null.
     
    sources68, Aug 11, 2012 IP
  5. seoexposure

    seoexposure Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Check if you had insert database connection details & it's all correct.Thanks!
     
    seoexposure, Aug 12, 2012 IP
  6. shubhamm

    shubhamm Member

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    I think you are facing the error because you don't have the database/ Table/ or any row and in Localhost you have so grab your database export it and import it
     
    shubhamm, Aug 12, 2012 IP
  7. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #7
    Since null means "never been written to", the only way would be to delete the row, then insert a new row with all the other fields (don't have cat3 in the list in the INSERT query). It's not a practical solution. Changing the WHERE to

    cat1='$cat1' AND cat2='$cat2' AND (cat3 is null or cat3 = '')

    is a better solution.
     
    Rukbat, Aug 12, 2012 IP