Hello, i made a simple shoutbox on my website but i want to check if the user filled in the blank Name and Message textfields. I did that like this.
The first problem now is that when someone leaves a blank name then the page partly refreshes, it will stop refreshing the page halfway cause the phpcode interupts it when the exit() function.
How can i do it so that when someone presses the "submit" button that it messagebox something and that it doesnt partly refresh the page.
<?
if (isset($_POST['submit'])) {
$name=$_POST['name'];
$message=$_POST['message'];
if($name=="")
{
exit();
}
// Connect to the database
...
...
...
//left the rest out, not of importanceTry using the isset() function to check your vars.
Here's an example:
<?
$var = "";
if(!isset($var))
{
die('Error message for missing vars goes in here');
}
elseif(isset($var))
{
echo('Rest of the code goes here if everything\'s okay');
}
?>
That, or you can use javascript to make an alert box pop upor don't use the exit function. jus thave the page come up again dispalying a error message, right above the form, in red.
The first problem now is that when someone leaves a blank name then the page partly refreshes, it will stop refreshing the page halfway cause the phpcode interupts it when the exit() function.
How can i do it so that when someone presses the "submit" button that it messagebox something and that it doesnt partly refresh the page.
<?
if (isset($_POST['submit'])) {
$name=$_POST['name'];
$message=$_POST['message'];
if($name=="")
{
exit();
}
// Connect to the database
...
...
...
//left the rest out, not of importanceTry using the isset() function to check your vars.
Here's an example:
<?
$var = "";
if(!isset($var))
{
die('Error message for missing vars goes in here');
}
elseif(isset($var))
{
echo('Rest of the code goes here if everything\'s okay');
}
?>
That, or you can use javascript to make an alert box pop upor don't use the exit function. jus thave the page come up again dispalying a error message, right above the form, in red.