![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
I am trying to use one page to display a form the when the page is first
accessed. Once the form is submitted then I want to use that page to process the information and display the results. The fun part to this is that I am getting this message: "Notice: Undefined index: search in C:\Documents and Settings...\db_search.php on line 13" The first time the page is loaded the _GET['search'] hasn't been used and so I think that is why it is giving me the notice. I am running this off of the apache server I set up on my home computer. Other php pages have worked fine but this one doesn't make sense. Here is the code for the page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DB Search Page</title> <link href="db_input.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $search = $_GET['search']; $self = $_SERVER['PHP_SELF']; if ($search != NULL) { (' <form action="'.$_SERVER["PHP_SELF"].'" method="GET"> <label>Search: <input type="text name="search" /> </label> <input type="submit" value="Find It Now!!!!" /> </form> '); } ?> </body> </html> |
| Sponsored Links |
|
|||
|
On Wed, 15 Oct 2008 17:10:16 +0000 (UTC), "UteFanJason"
<webforumsuser@macromedia.com> wrote: > $search = $_GET['search']; > $self = $_SERVER['PHP_SELF']; > if ($search != NULL) > { Change the above to: $self = $_SERVER['PHP_SELF']; if (!isset($_GET['search'])) { $search = $_GET['search']; Gary |
|
|||
|
Gary White wrote:
> if (!isset($_GET['search'])) > { > $search = $_GET['search']; That won't work. You've put the negative operator in there by mistake. It should be this: $search = isset($_GET['search']) ? $_GET['search'] : null; -- David Powers, Adobe Community Expert Author, "The Essential Guide to Dreamweaver CS3" (friends of ED) Author, "PHP Solutions" (friends of ED) http://foundationphp.com/ |
|
|||
|
Gary and David,
Thank you for your help. That fixed the problem. With my luck I will run into more while learning to create dynamic pages. But the help is appreciated. Thanks again. I haven't seen those other parts ---- isset($_GET['search']) ? $_GET['search'] : null; ---- before I will look into how and why those work like that. Thanks. |
|
|||
|
On Wed, 15 Oct 2008 19:32:23 +0100, David Powers <david@example.com>
wrote: >Gary White wrote: >> if (!isset($_GET['search'])) >> { >> $search = $_GET['search']; > >That won't work. You've put the negative operator in there by mistake. > >It should be this: > >$search = isset($_GET['search']) ? $_GET['search'] : null; You're right ... I think. The logic in the original post threw me. It was my understanding that the O/P wanted to display the form if it had not been submitted. The only thing the $search variable was being used for was to test that the form had been submitted. If you simply omitted the $search = $_GET['search'] line, it should work. ;-) Gary |
|
|||
|
Gary,
It is my objective to only display the form if it hasn't already been submitted. The next step is to display the results if there was a submission. I followed the suggestions and that did eliminate the notice I was getting but the form didn't show up at all. I changed the if statement and it now outputs the form no matter what. Also, I have been looking around and have yet to find the answer. I'm looking at the isset() function and the question mark in David's line $search = isset($_GET['search']) ? $_GET['search'] : null; What are they and how do they work? Thanks. |
|
|||
|
UteFanJason wrote:
> I'm looking > at the isset() function and the question mark in David's line > > $search = isset($_GET['search']) ? $_GET['search'] : null; > > What are they and how do they work? isset() tests whether a variable has been declared: http://docs.php.net/manual/en/function.isset.php The question mark followed by the colon (? is the conditional(ternary) operator: http://docs.php.net/manual/en/langua...comparison.php The following line: $search = isset($_GET['search']) ? $_GET['search'] : null; has the same meaning as this: if (isset($_GET['search'])) { $search = $_GET['search']; } else { $search = null; } -- David Powers, Adobe Community Expert Author, "The Essential Guide to Dreamweaver CS3" (friends of ED) Author, "PHP Solutions" (friends of ED) http://foundationphp.com/ |
|
|||
|
Those pages help. I didn't realize the ?: were together. Thanks.
Thanks for the other link. That will help too. So, since all of your help I have changed to code to the following and it doesn't seem to be setting the variable $_GET['search'] because when I submit it I am taken back to a page that has a blank form with the echo that the var has not been sent. **************************PHP CODE******************************** $self = $_SERVER['PHP_SELF']; if (!isset($_GET['search'])) { echo 'The variable search is not set'; echo '<form action="'.$self.'" method="GET">'; echo '<label>Search: <input type="text name="search" /></label>'; echo '<input type="submit" value="Find It Now!!!!" />'; echo '</form>'; } else { echo ' The variable search is set '; } ***********************END OF PHP CODE**************************** |
|
|||
|
On Wed, 15 Oct 2008 23:48:41 +0000 (UTC), "UteFanJason"
<webforumsuser@macromedia.com> wrote: > echo '<label>Search: <input type="text name="search" /></label>'; You're missing the closing quote after type="text above. Change it to: echo '<label>Search: <input type="text" name="search" /></label>'; Gary |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise