Jump to content

Recommended Posts

Posted

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

Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...