problems

This is a discussion on problems within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi list Hope somebody can help me. when i run this code <?php require ("header.php"); echo &...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-11-2003
simse
 
Posts: n/a
Default problems

Hi list
Hope somebody can help me.

when i run this code
<?php

require ("header.php");
echo "<h2>Add contact</h2>";

echo "
<table border=1>

<tr>


<form name=custom action=".$_SERVER['PHP_SELF']." method=POST>
<input type=hidden name=dirty value=0>
<td>First name</td><td><input type=text
name=txtFirstName></td><tr>
<td>Last name </td><td><input type=text
name=txtLastName></td><tr>
<td>Phone </td><td><input type=text name=txtPhone></td><tr>
<td>Mobil </td><td><input type=text name=txtMobilPhone></td><tr>
<td>Email </td><td><input type=text
name=txtEmailAddress></td><tr>
<td>Contact type </td><td><input type=text
name=txtContactType></td></tr>

</form>
</table>
<input type=submit onclick=\"custom.dirty.value=1\" value=\"Create new
contact\">";

if ( $_POST['dirty'] == 0 )
{
echo "her skal der kaldes kode til indsætte u mysql";
}
?>


I get the following message

Notice: Undefined index: dirty in d:\program files\apache
group\apache\htdocs\shj\add_contact.php on line 25

I have tried many dirrefent thingsnow but i can't get through....
please !!

regards
Simon


Reply With Quote
  #2 (permalink)  
Old 09-11-2003
Zurab Davitiani
 
Posts: n/a
Default Re: problems

simse wrote on Thursday 11 September 2003 15:15:

<snip>
> if ( $_POST['dirty'] == 0 )
> {
> echo "her skal der kaldes kode til indsætte u mysql";
> }
> ?>


<snip>

> Notice: Undefined index: dirty in d:\program files\apache
> group\apache\htdocs\shj\add_contact.php on line 25


Change the if condition to

isset($_POST['dirty'])

What is happening is that first time when you access the page, the "dirty"
form element has not been submitted and, therefore, does not exist in the
$_POST array. Hence, the message.

Having said that, the message is just a notice, it's not an error. You can
set what types of messages should display in your php.ini file.

Using isset() function should get rid of the notice.

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Reply With Quote
  #3 (permalink)  
Old 09-21-2003
Savut
 
Posts: n/a
Default Re: problems

False as PHP create the variables with default value on first use if not
defined before.

"Zurab Davitiani" <agt@mindless.com> wrote in message
news:0_68b.3424$kT.1675@newssvr25.news.prodigy.com ...
> simse wrote on Thursday 11 September 2003 15:15:
>
> <snip>
> > if ( $_POST['dirty'] == 0 )
> > {
> > echo "her skal der kaldes kode til indsætte u mysql";
> > }
> > ?>

>
> <snip>
>
> > Notice: Undefined index: dirty in d:\program files\apache
> > group\apache\htdocs\shj\add_contact.php on line 25

>
> Change the if condition to
>
> isset($_POST['dirty'])
>
> What is happening is that first time when you access the page, the "dirty"
> form element has not been submitted and, therefore, does not exist in the
> $_POST array. Hence, the message.
>
> Having said that, the message is just a notice, it's not an error. You can
> set what types of messages should display in your php.ini file.
>
> Using isset() function should get rid of the notice.
>
> --
> Business Web Solutions
> ActiveLink, LLC
> www.active-link.com/intranet/



Reply With Quote
  #4 (permalink)  
Old 09-22-2003
Andy Hassall
 
Posts: n/a
Default Re: problems

On Sun, 21 Sep 2003 09:25:03 -0400, "Savut" <webki@hotmail.com> wrote:

>"Zurab Davitiani" <agt@mindless.com> wrote in message
>news:0_68b.3424$kT.1675@newssvr25.news.prodigy.co m...
>> simse wrote on Thursday 11 September 2003 15:15:
>>
>> <snip>
>> > if ( $_POST['dirty'] == 0 )
>> > {
>> > echo "her skal der kaldes kode til indsætte u mysql";
>> > }
>> > ?>

>>
>> <snip>
>>
>> > Notice: Undefined index: dirty in d:\program files\apache
>> > group\apache\htdocs\shj\add_contact.php on line 25

>>
>> Change the if condition to
>>
>> isset($_POST['dirty'])
>>
>> What is happening is that first time when you access the page, the "dirty"
>> form element has not been submitted and, therefore, does not exist in the
>> $_POST array. Hence, the message.
>>
>> Having said that, the message is just a notice, it's not an error. You can
>> set what types of messages should display in your php.ini file.
>>
>> Using isset() function should get rid of the notice.


Yes - use isset(); don't just hide the warning by reducing the error_reporting
level in php.ini.

>False as PHP create the variables with default value on first use if not
>defined before.


No, it does not. Zurab is correct.

Please demonstrate the default values used for variables of each type if you
want to back up this statement.

<pre>
<?php
var_dump($_GET['notset']);
var_dump($_GET['notset']);
?>
</pre>

Outputs:

Notice: Undefined index: notset in /home/andyh/public_html/test.php on line 3
NULL

Notice: Undefined index: notset in /home/andyh/public_html/test.php on line 4
NULL

If your statement were correct, there would only be one warning. Use of a
variable (i.e. read) in PHP does not define it. Only writing to a variable
does.

--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:28 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0