Jump to content

Error message


pwes24

Recommended Posts

Let's say i want convert km to miles. so the first thing is to check user input. if its not there an echo error like "enter some number" shows up. The problem is that this error shows up the first time the page loads. How can i prevent it from doing so?

 

You need to do a CHECK first to see if they requested the data. I assume you have a submit button, we will call that "submit".

 

So you would just check if they pressed the button

 

<?php

if (isset($_POST['submit'])){
   //now put all the code here
}

?>

Link to comment
https://forums.phpfreaks.com/topic/80653-error-message/#findComment-409043
Share on other sites

 

What am I doing wrong here?

 

<body>

<?php

if (isset($_POST['submit'])){

$food=$_GET[food];

if (!empty($food)) {

echo "The foods selected are:<br />";

foreach($food as $foodstuff) {

echo $foodstuff.", ";

} else {

echo('check a box please');

}

}

}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

<fieldset>

<label>Italian <input name="food[]" type="checkbox" value="Italian" checked /></label>

<label>Mexican <input name="food[]" type="checkbox" value="Mexican" /></label>

<label>Chenese <input name="food[]" type="checkbox" value="Chenese" /></label>

</fieldset>

<input type="submit" value="submit" name="submit">

</body>

Link to comment
https://forums.phpfreaks.com/topic/80653-error-message/#findComment-409057
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.