Jump to content

Notice: Undefined index: sendit in C:\...


Wickham

Recommended Posts

I've got a test form working to show the data on the same page after processing and it works well but I've had to insert

error_reporting (E_ALL ^ E_NOTICE);

to get rid of this notice:-

Notice: Undefined index: sendit in C:\wamp\www\test\test-form4a.php on line 10

which is if($_POST['sendit'])

 

The php on first loading the page ignores the echos to display the data and uses the "else" to display the form. When the submit button is pressed the page loads again and $_POST['sendit'] then has some data to process, but on the first pass the sendit is undefined.

 

I've tried making it a variable like

if($_POST[$sendit])

or

if($_POST['$sendit'])

with

$sendit = $_POST['sendit'];

but the notice still shows and the form doesn't process.

 

I've also tried putting the variable is different places.

 

Is there a way to get it right without the exception code?

 

>




PHP test



This is testing WampServer2.
error_reporting (E_ALL ^ E_NOTICE);
if($_POST['sendit'])
{
$rating = $_POST['rating'];
$item = $_POST['item'];
echo  "You rated {$item} as {$rating} out of 10.";
echo "
Thank You.";
}
else 
{ echo "Please submit form";
?>
</pre>
<form action="test-form4a.php" method="post">

Song 1
Song 2

Rating (out of 10 please):  

</form>
<br><br>}<br>?><br><br><br

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...