GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Jun-2004, 08:06
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road

(isset)


I use a search form that sends the relevant info to a results page
Example code
HTML Code:
<tr> <td height="25" class="textfont">&nbsp;Fuel Type:</td> <td height="25" class="textfont"> <select name="Rpic" class="droplist"> <option value="0" selected>Any Fuel</option> <option value="Petrol">Petrol</option> <option value="Diesel">Diesel</option> </select> </td></tr>


This is inserted into my search query as
PHP Code:

if(isset($Rpic)and ($Rpic != 0 ))
        {
            if($state == 1)
                $sql1 .= "AND rem_pic_path4=$Rpic ";
            else
                $sql1 .= "rem_pic_path4=$Rpic ";
            $state = 1;
        } 



All the other sections work apart from this one. Can anybody see what I am doing wrong?
It is the only section that doesnt work so I am missing something.
Last edited by JdS : 20-Jun-2004 at 04:14. Reason: Please insert [php] & [/php] tags between your example PHP codes
  #2  
Old 20-Jun-2004, 04:38
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Despite having almost 100 posts to your credit on GIDForums™, I am surprised that you still use [ QUOTE ] bbcode tag to highlight your code examples. What is wrong with using HTML or PHP bbcodes?

Anyway, what seems to be the problem with your code actually? Is it just that $Rpic is not set/blank or the 'created' SQL is failing? Can you echo the $Rpic value in a test page?

If you're using the POST method in your form and your REGISTER GLOBALS setting is OFF, then you need to use $_POST['Rpic'] to grab the form's value in your script. Somehow I think you know that already, so it must be something else that you omitted sharing in your first message.
  #3  
Old 20-Jun-2004, 06:12
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road
My first reprimand.
Quote:
Is it just that $Rpic is not set/blank or the 'created' SQL is failing? Can you echo the $Rpic value in a test page?

$Rpic value can be displayed on the page so the information is getting to my results page.
All other aspects of the search are working but the $Rpic is being ignored for some reason. If I search for just a Diesel all listings are displayed as if the $Rpic was not present.

(I hereby promise to use the correct tags for codes on all my posts, scouts honour. )
  #4  
Old 20-Jun-2004, 06:17
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
No, we don't do the 'reprimand' thingy here... just confused why you'd want me to keep editing your posts, that's all!

OK, I see the issue now that I've narrowed my attention to the SQL bit off your example code; you forgot the single quotes around $Rpic!

So, your code could look a bit like this?
PHP Code:

if(isset($Rpic)and ($Rpic != 0 ))
    {
      if($state == 1)
        $sql1 .= "AND rem_pic_path4='$Rpic' ";
      else
        $sql1 .= "rem_pic_path4='$Rpic' ";
      $state = 1;
    } ?> 

  #5  
Old 20-Jun-2004, 06:30
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road
Nope tried with and without but still ignoring $Rpic
  #6  
Old 20-Jun-2004, 06:33
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Have you tried 'echo'-ing $sqll just to see what is being sent to the MySQL server?
  #7  
Old 20-Jun-2004, 06:34
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road
If I use
PHP Code:

if(isset($Rpic))
        {
            if($state == 1)
                $sql1 .= "AND rem_pic_path4='$Rpic' ";
            else
                $sql1 .= "AND rem_pic_path4='$Rpic' ";
            $state = 1;
        } 


It will search for Diesel or Petrol but of course my problem arises if I want both Fuel Types.
  #8  
Old 20-Jun-2004, 06:48
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road
OK now we are getting somewhere:

'echo'-ing sql1 shows that using code last posted without
PHP Code:

and $Rpic != 0 


that $pic is being included in the query.

'echo'-ing sql1 shows that using code including
PHP Code:

and $Rpic != 0 


that $pic is not being included in the query.
  #9  
Old 20-Jun-2004, 07:17
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road
Got it to work
I used
HTML Code:
<tr> <td height="25" class="textfont">&nbsp;Fuel Type:</td> <td height="25" class="textfont"> <select name="Rpic" class="droplist"> <option value="Any" selected>Any Fuel</option> <option value="Petrol">Petrol</option> <option value="Diesel">Diesel</option> </select> </td> </tr>

and

PHP Code:

if(isset($Rpic) and ($Rpic!=Any))
        {
            if($state == 1)
                $sql1 .= "AND rem_pic_path4='$Rpic' ";
            else
                $sql1 .= "rem_pic_path4='$Rpic' ";
            $state = 1;
        } 



What the difference Any made from 0 I am unsure??? but it now works.
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.