Jump to content

Recommended Posts

Checking to see if I am on a good path.

 

I have a search form that has a drop down and then input. Based on the drop down I will search different

tables. I am very new at coding and would like to see if my thought process is going in the

right direction.

 

Can someone tell me if I have chosen the most applicable IF statement and if I have the general idea?

 

 

$field=$_GET["field"];

if ($field == "artist")
echo "You have choosen to search for an Artist.";

elseif ($field == "artwork")
echo "Art work it is!";

elseif ($field == "keywords")
echo "I will check all keywords.";

else
echo "I will check everything.";

 

Obviously I'm not going to have the ECHO's but will have my search code. But going simple for now.

 

-----

 

My search form

 

<form name="search" method="get" action="artist.php" onsubmit="return checkform(this);">

Seach 

<select NAME="field">

<option value="all">All</option>

<option value="artist">Artists</option>

<option value="artwork">Art Works</option>

<option value="keywords">Keywords</option>

</Select>

for <input type="text" name="find" />


<input type="hidden" name="search" value="yes" />

<input type="submit" name="search" value="search" />

</form>

 

 

Link to comment
https://forums.phpfreaks.com/topic/132609-if-statment/
Share on other sites

Aside from validating form input (which I assume you're working on), your code seems to be good so far. Of course, of course you might want to add a 'Search All' option to the select menu and then use the 'else' statement to return an error along the lines of, "invalid option"

 

Also, not that's absolutely necessary, but you could also use POST for this as it wouldn't be passed through the URL.

 

Have you tried testing this code yet?

Link to comment
https://forums.phpfreaks.com/topic/132609-if-statment/#findComment-689538
Share on other sites

I have it working and I used a javascript that has a stupid pop-up if 'find' is left empty. Using the javascript would I need another else statement to return an error, can I not just use another else statement to validate a blank 'find' ?

 

I was thinking I would need all the if/else statements because the information lies in different tables and I didn't want to search one table for info that I know isn't there, also if looking for an artist their name can also be included in an art work and I want to be specific.

 

 

Link to comment
https://forums.phpfreaks.com/topic/132609-if-statment/#findComment-689627
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.