www.webdeveloper.com
Results 1 to 7 of 7

Thread: Help with mysql query syntax using php

  1. #1
    Join Date
    Jan 2006
    Posts
    17

    Help with mysql query syntax using php

    I'm having a problem with getting a query to execute properly it works part of the time but on certain occassions it just will not execute.

    this is a print out of the query string:

    SELECT * FROM `orders` WHERE `cust`='' AND `job`='7515 HAVENS ROAD RUKSUJJAR RES.' AND `worder`='W38787'

    And I'm sure that this should bring up at least one row.

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    could you explain a little bit more?
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Jan 2006
    Posts
    17
    basically it should come up with one row and when it is executed it finds no rows. On other variables it works just fine, but when these specific variables come up it doesn't find the row.

    here's the php

    PHP Code:
            $temp_query="SELECT * FROM `orders` WHERE `cust`='$cust' AND `job`='$jobname' AND `worder`='$worder'";
            
    $temp_result=mysql_query($temp_query);
            if (!
    mysql_num_rows($temp_result) || mysql_num_rows($temp_result)==0){
                    
    $temp_query="insert into orders values('', '$worder', '$cust', '$jobname', '$date', '', '$house', '$sales')";
                    
    $temp_result=mysql_query($temp_query);

    It should check if those particular variables are in the database...if their not then they get put in.

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    just a comment or two.

    - you're not actually concerned with the data in the select statement, just the number of rows, so maybe use a count instead?
    - have you tried executing the exact same query outside of PHP? does it return rows there?
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  5. #5
    Join Date
    Jan 2006
    Posts
    17
    Could you explain what you mean by a count?

    And Yes I've tried to execute the query elsewhere and it still didn't work which I don't understand.

  6. #6
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    if the query doesn't work, then that means its not returning any results. Once you can verify that the query will work, try putting it back into PHP in its new format.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  7. #7
    Join Date
    Jan 2006
    Posts
    17
    I fixed it, I'm an idiot. I set the job to varchar 30 and it was 31 characters so when it checked it was missing a period.

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