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 &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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/ |
|
|||
|
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/ |
|
|||
|
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) |