Undefined Index

Codes here !

Moderators: macek, egami, gesf

jagjittcl
New php-forum User
New php-forum User
Posts: 9
Joined: Wed Jul 03, 2013 10:14 pm

Undefined Index

Postby jagjittcl » Thu Jul 18, 2013 9:35 am

Hi

In the below code it is giving me undefined index emlsubject,emlbody on this line
if( $_POST['emlsubject'] || $_POST['emlbody'] )

<?php
if( $_POST['emlsubject'] || $_POST['emlbody'] )
{
echo $_POST['emlsubject'] ;
echo $_POST['emlbody'];
}
?>
<html>
<body>
<form method="POST" action="<?php $_PHP_SELF ?>">
<label>Subject For Email : </label>
<input type="text" id="emlsubject" name = "emlsubject" size="60" /> </br>
<label>Body Of Email : </label>
<textarea id="emlbody" name="emlbody" rows="8" cols="60" > </textarea> </br>
<input type="Submit" name = "submit" value="submit" />
</form>
</body>
</html>

Thanks

pbs
New php-forum User
New php-forum User
Posts: 39
Joined: Sat May 11, 2013 1:40 am
Location: Nashik, India
Contact:

Re: Undefined Index

Postby pbs » Thu Jul 18, 2013 8:08 pm

as no values are assign to emlsubject, emlbody, so it is it's giving notice errors

you can disable these notice errors from php.ini

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Undefined Index

Postby johnj » Thu Jul 18, 2013 9:07 pm

You should not disable notice errors. Try to find why the form variables are not set. Also, you should access those form variable only after you have submitted the form.

jagjittcl
New php-forum User
New php-forum User
Posts: 9
Joined: Wed Jul 03, 2013 10:14 pm

Re: Undefined Index

Postby jagjittcl » Fri Jul 19, 2013 1:05 am

Hi Johnj

Can you please guide me what is wrong in the above code

Thanks

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Undefined Index

Postby johnj » Fri Jul 19, 2013 5:44 am

try to understand how to submit a form, what happens when we submit a form etc. Only then can I fix this code. Take a look at this tutorial,
http://www.homeandlearn.co.uk/php/php4p5.html


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest