Wickham Posted January 21, 2009 Report Share Posted January 21, 2009 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 Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 21, 2009 Report Share Posted January 21, 2009 Instead of if($_POST['sendit']) I usually use if(isset($_POST['sendit'])) Quote Link to comment Share on other sites More sharing options...
Wickham Posted January 21, 2009 Author Report Share Posted January 21, 2009 Thanks Ben.. I had tried if(!isset($_POST['sendit'])) which has ! before isset as shown on this webpage http://www.dmxzone.com/ShowDetail.asp?NewsId=13811 but it didn't work. Why did that web answer include the ! Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 21, 2009 Report Share Posted January 21, 2009 the "!" stands for "not", so that statement would read "if $_POST['sendit'] isn't set, then..." basically, to use the above statement, you would have to switch around your logic. If it isn't set, display the form, otherwise, process the form. Quote Link to comment Share on other sites More sharing options...
Wickham Posted January 21, 2009 Author Report Share Posted January 21, 2009 Uh! I could have guessed that! :/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.