Jump to content

Prevent code from running when page loads


Ramtree

Recommended Posts

i have a php page where user fills up the forms.

 

this is the code i use:

if(empty($_POST['form']))
{
echo "please fill in the forms";
}
else
{
mysql_query($sql);
}

 

when the page loads, it would display "please fill in the forms". i want to prevent the php code from running when the user first go to the page. please tell me how to do so, thanks.

Link to comment
Share on other sites

$error=0;


if(!empty($_POST) && empty($_POST['form1']))
{
echo "Please input the Question.";
echo "<br>";
$error++;
}

if(!empty($_POST) && empty($_POST['form2']))
{
echo "Please input the Answer Option 1.";
echo "<br>";
$error++;
}

if(!empty($_POST) && empty($_POST['form3']))
{
echo "Please input the Answer Option 2.";
echo "<br>";
$error++;
}

if(!empty($_POST) && empty($_POST['form4']))
{
echo "Please input the Answer Option 3.";
echo "<br>";
$error++;
}

if(!empty($_POST) && empty($_POST['form5']))
{
echo "Please input the Answer Option 4.";
echo "<br>";
$error++;
}

if(!empty($_POST) && empty($_POST['form6']))
{
echo "Please input the Correct Answer.";
echo "<br>";
$error++;
}


if($error==0)
{
echo "Request submitted successfully.";
mysql_query($sql);
}

 

 

if were to use the code like this, the page would display "Request submitted successfully." and blank data would be inserted in to the database. i want to prevent this code from running as well. pls help me, thanks. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.