Adobe Dreamweaver Forums



Last 10 THreads :         Trouble using variables to name and instantiateTextFields (Last Post : jc_2006 - Replies : 1 - Views : 2 )           »          Background color code is not working. Please help (Last Post : Tim G - Replies : 9 - Views : 10 )           »          error (Last Post : Tim G - Replies : 1 - Views : 2 )           »          DWCS4 Menus (Last Post : DouglasWD - Replies : 0 - Views : 1 )           »          Can't open more than one Macromedia product at a time (Last Post : ChandaBB - Replies : 7 - Views : 8 )           »          DWCS4 Fade/Appear image load question (Last Post : DouglasWD - Replies : 0 - Views : 1 )           »          NetStream progressive FLV download current frame (Last Post : AsafH - Replies : 0 - Views : 1 )           »          Creating Newsletters (Last Post : Yovav - Replies : 2 - Views : 10 )           »          CS4 Div Tags Help Needed (Last Post : Ian Edwards - Replies : 4 - Views : 5 )           »          Letters are cutoff (Last Post : shlomi75 - Replies : 0 - Views : 1 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Dreamweaver: Main > Dreamweaver General
 
Tags:



Reply
  #1 (permalink)  
Old 10-15-2008, 06:11 PM
UteFanJason
 
Posts: n/a
Diggs:
Default PHP Notice Problem

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>



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-15-2008, 06:41 PM
Gary White
 
Posts: n/a
Diggs:
Default Re: PHP Notice Problem

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
Reply With Quote
  #3 (permalink)  
Old 10-15-2008, 07:41 PM
David Powers
 
Posts: n/a
Diggs:
Default Re: PHP Notice Problem

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/
Reply With Quote


  #4 (permalink)  
Old 10-15-2008, 08:10 PM
UteFanJason
 
Posts: n/a
Diggs:
Default Re: PHP Notice Problem

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.


Reply With Quote
  #5 (permalink)  
Old 10-15-2008, 09:26 PM
Gary White
 
Posts: n/a
Diggs:
Default Re: PHP Notice Problem

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
Reply With Quote
  #6 (permalink)  
Old 10-15-2008, 10:01 PM
UteFanJason
 
Posts: n/a
Diggs:
Default Re: PHP Notice Problem

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.

Reply With Quote


  #7 (permalink)  
Old 10-15-2008, 11:01 PM
David Powers
 
Posts: n/a
Diggs:
Default Re: PHP Notice Problem

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/
Reply With Quote
  #8 (permalink)  
Old 10-16-2008, 12:50 AM
UteFanJason
 
Posts: n/a
Diggs:
Default Re: PHP Notice Problem

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****************************

Reply With Quote
  #9 (permalink)  
Old 10-16-2008, 05:30 AM
Gary White
 
Posts: n/a
Diggs:
Default Re: PHP Notice Problem

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
Reply With Quote


  #10 (permalink)  
Old 10-16-2008, 05:14 PM
UteFanJason
 
Posts: n/a
Diggs:
Default Re: PHP Notice Problem

Thanks again. Good eye.

It is always a lot better to have another set of eyes to proofread material.
Reply With Quote
Reply


Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 11:11 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk