...

View Full Version : Require email on database submission form



crazykid
03-23-2010, 10:43 PM
What code do I use to have a person type data on to a form and submit it so the data goes into a database but if they don't type an email into the email textbox, the form won't let the person submit the form?

stevey17
03-23-2010, 11:01 PM
basically use a if statement with an isset fuction



<?php
if(isset($_POST[email])){
//code to send it to database
}
else{
//display form
}
?>

DJCMBear
03-24-2010, 01:26 AM
basically use a if statement with an isset fuction



<?php
if(isset($_POST[email])){
//code to send it to database
}
else{
//display form
}
?>


stevey17 that wouldnt validate that the user inputted an email they could just put hello and it would still send the data

what you would need to do crazykid is this:


<?php
if(isset($_POST['email']) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) {
//code to send it to database
}
else{
//display form
}
?>

crazykid
03-24-2010, 01:53 AM
Is this the code that sends the email to the database?


if(isset($_POST['email']) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) {

Is this the code for the display form?


else{

}

This is the code I got for the email input textbox...it displays the textbox and sends the data to the database:


<td width="100%" align="right" valign="top">Email:<input type="text" name="Email" value="" size="20" maxlength="255"></td>

This is the code I got to match the data inputted with the database variable:


$quest_ipaddress=$_SERVER['IPAddress'];

Any way of merging the codes together with the codes you gave me?

DJCMBear
03-24-2010, 01:59 AM
<?php
if(isset($_POST['Email']) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email'])) {
// this is where you send the data to the database
}else{
// this is where you put your form for the user to use
}
?>

crazykid
03-24-2010, 02:07 AM
Does this code look good:


<?php
if(isset($_POST['IPAddress']) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['IPAddress'])) {
// this is where you send the data to the database
}else{
?>
<td width="100%" align="right" valign="top">Email:<input type="text" name="Email" value="" size="20" maxlength="255"></td>
<?
// this is where you put your form for the user to use
}
?>

Problem is when I test it and put in my email, the code I use to send people back if they didn't put in their email still doesn't let me go through.

masterofollies
03-24-2010, 02:09 AM
Another way would be this.


if (EMPTY($_post['email'])) {
//Email is empty
}
else {
//Continue processing
}

DJCMBear
03-24-2010, 02:09 AM
Does this code look good:


<?php
if(isset($_POST['IPAddress']) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['IPAddress'])) {
// this is where you send the data to the database
}else{
?>
<td width="100%" align="right" valign="top">Email:<input type="text" name="Email" value="" size="20" maxlength="255"></td>
<?
// this is where you put your form for the user to use
}
?>

Problem is when I test it and put in my email, the code I use to send people back if they didn't put in their email still doesn't let me go through.

No you need to write this:

<?php
if(isset($_POST['IPAddress']) && isset($_POST['Email']) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email'])) {
// this is where you send the data to the database
}else{
?>
<td width="100%" align="right" valign="top">Email:<input type="text" name="Email" value="" size="20" maxlength="255"></td>
<?
// this is where you put your form for the user to use
}
?>

EDIT:
And the whole form needs to go where the td tag is.

crazykid
03-24-2010, 02:19 AM
This is what my whole file looks like:


<? include "/home1/sparkonl/public_html/fiesta/questdb/core_quest_functions.php";
?>



<?
$quest_category = $_POST['Category'];
$quest_name = $_POST['Name'];
$quest_level = $_POST['Level'];
$quest_location = $_POST['Location'];
$quest_npc = $_POST['NPC'];
$quest_objective = $_POST['Objective'];
$quest_procedure = $_POST['Procedure'];
$quest_rewards = $_POST['Rewards'];
$quest_pre = $_POST['Prereq'];
$quest_repeatable = $_POST['Repeatable'];
$quest_ipaddress=$_SERVER['IPAddress'];




$error = '0';
//If they are all blank we just say to compose a message
if(!$quest_category AND !$quest_name)
{
?>
<p><b><center>Please complete the quest information<center></b></p>
<br>
<?
}

//Since this form was partially filled out we need to return an error message
else
{

//If the variable error is not set to zero, we have a problem and should show the error message
if (!$quest_name)
{
$error = 'You must enter the quests name';
}
if (!$quest_email)
{
$error = 'You must enter your email address';
}

if($error != '0')
{
echo "<p>$error</p><br>";
}

//There are no errors so far which means the form is completely filled out
else
{
$category_check = $quest_category;
if($category_check > '0')
{



//add quest into the database
mysql_query("INSERT INTO quest (Category, Name, Level, Location, NPC, Objective, `Procedure`, Rewards, Prereq, Repeatable, Email, IPAddress) VALUES('$quest_category', '$quest_name', '$quest_level', '$quest_location', '$quest_npc', '$quest_objective', '$quest_procedure', '$quest_rewards', '$quest_pre', '$quest_repeatable', '$quest_email', '$quest_ipaddress')") or die (mysql_error());

if ($quest_category = 1) {
$category_name ="quest1-10.php";
}
elseif ($quest_category = 2) {
$category_name ="quest11-20.php";
}
elseif ($quest_category = 3) {
$category_name ="quest21-30.php";
}
elseif ($quest_category = 4) {
$category_name ="quest31-40.php";
}
elseif ($quest_category = 5) {
$category_name ="quest41-50.php";
}
elseif ($quest_category = 6) {
$category_name ="quest51-60.php";
}
elseif ($quest_category = 7) {
$category_name ="quest61-70.php";
}
elseif ($quest_category = 8) {
$category_name ="quest71-80.php";
}
elseif ($quest_category = 9) {
$category_name ="quest81-90.php";
}
elseif ($quest_category = 10) {
$category_name ="quest91-100.php";
}
elseif ($quest_category = 11) {
$category_name ="quest100+.php";
}
elseif ($quest_category = 12) {
$category_name ="questkq.php";
}
else {
echo ERROR;
}

$link_name = str_replace(" ", "_", "$quest_name");
$quest_link = "http://fiestavault.sparkonline.net/quest/$category_name#$link_name";
mysql_query("INSERT INTO master (Name, Link, Namelink) VALUES('$quest_name', '$quest_link', '$link_name')") or die (mysql_error());


//Let the user know everything went ok.
echo "<center><p><b>You have successfully submitted an quest!</b></p></center><br>";
}
//Since they are trying to send messages faster than every 15 seconds, give them an error message
}
//If they mis spelled or, made up a username, then give an error message telling them its wrong.
}

//Since we may have set the error variable to something while trying to send the message, we need another error check
if($error != '0')
{
echo "<p>$error</p><br>";
}

else
{
//Here's the form for the input
?> <center>
<form name="send" method="post" action="submitquest.php">
<table width="100%">
<tr>
<td width="150px" align="center" valign="top"><p><b>Quest Category</b></p> <SELECT NAME="Category">
<OPTION VALUE="">Select a category</OPTION>
<OPTION VALUE=""></OPTION>
<OPTION VALUE="1">Level 1-10</OPTION>
<OPTION VALUE="2">Level 11-20</OPTION>
<OPTION VALUE="3">Level 21-30</OPTION>
<OPTION VALUE="4">Level 31-40</OPTION>
<OPTION VALUE="5">Level 41-50</OPTION>
<OPTION VALUE="6">Level 51-60</OPTION>
<OPTION VALUE="7">Level 61-70</OPTION>
<OPTION VALUE="8">Level 71-80</OPTION>
<OPTION VALUE="9">Level 81-90</OPTION>
<OPTION VALUE="10">Level 90-100</OPTION>
<OPTION VALUE="11">Level 100+</OPTION>
<OPTION VALUE="12">Kingdom Quest</OPTION>
</SELECT></td></tr>
<tr><td>
<center><b>Quest Information</b></center>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="50%" align="left" valign="top"><p>Quest Name: <input type="text" name="Name" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting Level: <input type="text" name="Level" value="" size="5" maxlength="5"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Starting Location: <input type="text" name="Location" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting NPC: <input type="text" name="NPC" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Objective:<textarea name="Objective" type="text" id="Objective" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Procedure:<textarea name="Procedure" type="text" id="Procedure" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Rewards:<textarea name="Rewards" type="text" id="Rewards" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Pre-Requisites:<input type="text" name="Pre" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="100%" align="left" valign="top">Repeatable: No<input type="RADIO" name="Repeatable" value="No" checked> Yes<input type="RADIO" name="Repeatable" value="Yes"></td>
</tr>
<tr>
<?php
if(isset($_POST['IPAddress']) && isset($_POST['Email']) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email'])) {
// this is where you send the data to the database
}else{
?>
<td width="100%" align="right" valign="top">Email:<input type="text" name="Email" value="" size="20" maxlength="255"></td>
<?
// this is where you put your form for the user to use
}
?>
</tr>
<tr>
<td><input type="reset" value="Reset" /></td>
<td><input type="submit" name="Submit" value="Submit quest"></td>
</tr>
</table>
</center>
</form>
<?
}
?>

And when I input my email address I still get a message telling me that I need to enter an email address.

DJCMBear
03-24-2010, 02:26 AM
This is how you should do it with the whole form inside the else statement:


<?php
if(isset($_POST['IPAddress']) && isset($_POST['Email']) && preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $_POST['Email'])) {
// this is where you send the data to the database
}else{
?>
<form name="send" method="post" action="submitquest.php">
<table width="100%">
<tr>
<td width="150px" align="center" valign="top"><p><b>Quest Category</b></p> <SELECT NAME="Category">
<OPTION VALUE="">Select a category</OPTION>
<OPTION VALUE=""></OPTION>
<OPTION VALUE="1">Level 1-10</OPTION>
<OPTION VALUE="2">Level 11-20</OPTION>
<OPTION VALUE="3">Level 21-30</OPTION>
<OPTION VALUE="4">Level 31-40</OPTION>
<OPTION VALUE="5">Level 41-50</OPTION>
<OPTION VALUE="6">Level 51-60</OPTION>
<OPTION VALUE="7">Level 61-70</OPTION>
<OPTION VALUE="8">Level 71-80</OPTION>
<OPTION VALUE="9">Level 81-90</OPTION>
<OPTION VALUE="10">Level 90-100</OPTION>
<OPTION VALUE="11">Level 100+</OPTION>
<OPTION VALUE="12">Kingdom Quest</OPTION>
</SELECT></td></tr>
<tr><td>
<center><b>Quest Information</b></center>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="50%" align="left" valign="top"><p>Quest Name: <input type="text" name="Name" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting Level: <input type="text" name="Level" value="" size="5" maxlength="5"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Starting Location: <input type="text" name="Location" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting NPC: <input type="text" name="NPC" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Objective:<textarea name="Objective" type="text" id="Objective" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Procedure:<textarea name="Procedure" type="text" id="Procedure" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Rewards:<textarea name="Rewards" type="text" id="Rewards" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Pre-Requisites:<input type="text" name="Pre" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="100%" align="left" valign="top">Repeatable: No<input type="RADIO" name="Repeatable" value="No" checked> Yes<input type="RADIO" name="Repeatable" value="Yes"></td>
</tr>
<tr>
<td width="100%" align="right" valign="top">Email:<input type="text" name="Email" value="" size="20" maxlength="255"></td>
</tr>
<tr>
<td><input type="reset" value="Reset" /></td>
<td><input type="submit" name="Submit" value="Submit quest"></td>
</tr>
</table>
</center>
</form>
<? } ?>


EDIT:
you dont have email set in these:


$quest_category = $_POST['Category'];
$quest_name = $_POST['Name'];
$quest_level = $_POST['Level'];
$quest_location = $_POST['Location'];
$quest_npc = $_POST['NPC'];
$quest_objective = $_POST['Objective'];
$quest_procedure = $_POST['Procedure'];
$quest_rewards = $_POST['Rewards'];
$quest_pre = $_POST['Prereq'];
$quest_repeatable = $_POST['Repeatable'];
$quest_ipaddress =$_SERVER['IPAddress'];

crazykid
03-24-2010, 02:39 AM
http://fiesta.sparkonline.net/questdb/admin/submitquest.php

Yea, I run a website based on an online game and the form allows a user to submit information about a quest into any one of the categories in the drop-down menu. I want to put in the email verification because I'm going to do an event for people and I need email verification.

So where would those variables go?

DJCMBear
03-24-2010, 02:47 AM
So where would those variables go?

They are your vars but i was saying you are checking for $quest_email when you haven't sent it in that var list.

crazykid
03-24-2010, 03:01 AM
Yea, I was going to use this as the var for the email input:


$quest_ipaddress=$_SERVER['IPAddress'];

But I needed that code you posted up the prevents random stuff from being put in as an email. How would I merge your code with the code I had originally?

DJCMBear
03-24-2010, 03:11 AM
Yea, I was going to use this as the var for the email input:


$quest_ipaddress=$_SERVER['IPAddress'];

But I needed that code you posted up the prevents random stuff from being put in as an email. How would I merge your code with the code I had originally?


Why use an email input is your going to call a server ip code that defetes the object abit.
Your still checking for $quest_email in your code when you dont have a var for it thats why your getting the email error.
Checking the inputted email is what you asked for so I gave you the code to do it so the users ip address cant be used seeing as its not an email address.
And to merge both together my code checks the email input nothing else so use that for $_POST['Email'] and nothing else.
EDIT:
try this:


<? include "/home1/sparkonl/public_html/fiesta/questdb/core_quest_functions.php";
?>

<?
$quest_category = $_POST['Category'];
$quest_email=$_POST['Email'];
$quest_name = $_POST['Name'];
$quest_level = $_POST['Level'];
$quest_location = $_POST['Location'];
$quest_npc = $_POST['NPC'];
$quest_objective = $_POST['Objective'];
$quest_procedure = $_POST['Procedure'];
$quest_rewards = $_POST['Rewards'];
$quest_pre = $_POST['Prereq'];
$quest_repeatable = $_POST['Repeatable'];
$quest_ipaddress=$_SERVER['IPAddress'];
$quest_email=$_POST['Email'];
$error = '0';
//If they are all blank we just say to compose a message
if(!$quest_category AND !$quest_name)
{
?>
<p><b><center>Please complete the quest information<center></b></p>
<br>
<?
}

//Since this form was partially filled out we need to return an error message
else
{
//If the variable error is not set to zero, we have a problem and should show the error message
if (!$quest_name)
{
$error = 'You must enter the quests name';
}
if (!$quest_email)
{
$error = 'You must enter your email address';
}
if($error != '0')
{
echo "<p>$error</p><br>";
}

//There are no errors so far which means the form is completely filled out
else
{
$category_check = $quest_category;
if($category_check > '0')
{
if ($quest_category = 1) {
$category_name ="quest1-10.php";
}
elseif ($quest_category = 2) {
$category_name ="quest11-20.php";
}
elseif ($quest_category = 3) {
$category_name ="quest21-30.php";
}
elseif ($quest_category = 4) {
$category_name ="quest31-40.php";
}
elseif ($quest_category = 5) {
$category_name ="quest41-50.php";
}
elseif ($quest_category = 6) {
$category_name ="quest51-60.php";
}
elseif ($quest_category = 7) {
$category_name ="quest61-70.php";
}
elseif ($quest_category = 8) {
$category_name ="quest71-80.php";
}
elseif ($quest_category = 9) {
$category_name ="quest81-90.php";
}
elseif ($quest_category = 10) {
$category_name ="quest91-100.php";
}
elseif ($quest_category = 11) {
$category_name ="quest100+.php";
}
elseif ($quest_category = 12) {
$category_name ="questkq.php";
}
else {
echo ERROR;
}

$link_name = str_replace(" ", "_", "$quest_name");
$quest_link = "http://fiestavault.sparkonline.net/quest/$category_name#$link_name";
mysql_query("INSERT INTO master (Name, Link, Namelink) VALUES('$quest_name', '$quest_link', '$link_name')") or die (mysql_error());

//Let the user know everything went ok.
echo "<center><p><b>You have successfully submitted an quest!</b></p></center><br>";
}
//Since they are trying to send messages faster than every 15 seconds, give them an error message
}
//If they mis spelled or, made up a username, then give an error message telling them its wrong.
}

//Since we may have set the error variable to something while trying to send the message, we need another error check
if($error != '0')
{
echo "<p>$error</p><br>";
}else{
//Here's the form for the input
?>
<?php
if(isset(isset($quest_email) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $quest_email)) {
mysql_query("INSERT INTO quest (Category, Name, Level, Location, NPC, Objective, `Procedure`, Rewards, Prereq, Repeatable, Email, IPAddress) VALUES('$quest_category', '$quest_name', '$quest_level', '$quest_location', '$quest_npc', '$quest_objective', '$quest_procedure', '$quest_rewards', '$quest_pre', '$quest_repeatable', '$quest_email', '$quest_ipaddress')") or die (mysql_error());
}else{
?>
<center>
<form name="send" method="post" action="submitquest.php">
<table width="100%">
<tr>
<td width="150px" align="center" valign="top"><p><b>Quest Category</b></p> <SELECT NAME="Category">
<OPTION VALUE="">Select a category</OPTION>
<OPTION VALUE=""></OPTION>
<OPTION VALUE="1">Level 1-10</OPTION>
<OPTION VALUE="2">Level 11-20</OPTION>
<OPTION VALUE="3">Level 21-30</OPTION>
<OPTION VALUE="4">Level 31-40</OPTION>
<OPTION VALUE="5">Level 41-50</OPTION>
<OPTION VALUE="6">Level 51-60</OPTION>
<OPTION VALUE="7">Level 61-70</OPTION>
<OPTION VALUE="8">Level 71-80</OPTION>
<OPTION VALUE="9">Level 81-90</OPTION>
<OPTION VALUE="10">Level 90-100</OPTION>
<OPTION VALUE="11">Level 100+</OPTION>
<OPTION VALUE="12">Kingdom Quest</OPTION>
</SELECT></td></tr>
<tr><td>
<center><b>Quest Information</b></center>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="50%" align="left" valign="top"><p>Quest Name: <input type="text" name="Name" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting Level: <input type="text" name="Level" value="" size="5" maxlength="5"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Starting Location: <input type="text" name="Location" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting NPC: <input type="text" name="NPC" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Objective:<textarea name="Objective" type="text" id="Objective" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Procedure:<textarea name="Procedure" type="text" id="Procedure" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Rewards:<textarea name="Rewards" type="text" id="Rewards" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Pre-Requisites:<input type="text" name="Pre" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="100%" align="left" valign="top">Repeatable: No<input type="RADIO" name="Repeatable" value="No" checked> Yes<input type="RADIO" name="Repeatable" value="Yes"></td>
</tr>
<tr>
<td width="100%" align="right" valign="top">Email:<input type="text" name="Email" value="" size="20" maxlength="255"></td>
</tr>
<tr>
<td><input type="reset" value="Reset" /></td>
<td><input type="submit" name="Submit" value="Submit quest"></td>
</tr>
</table>
</form>
</center>
<? } } ?>

crazykid
03-24-2010, 03:30 AM
Error:


Parse error: syntax error, unexpected T_ISSET, expecting T_STRING or T_VARIABLE or '$' in /home1/sparkonl/public_html/fiesta/questdb/admin/submitquest.php on line 111

Code:


if(isset(isset($quest_email) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $quest_email)) {

DJCMBear
03-24-2010, 03:37 AM
Error:



Code:


if(isset(isset($quest_email) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $quest_email)) {



this:

if(isset(isset($quest_email) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $quest_email)) {

should be this:

if(isset($quest_email) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $quest_email)) {



sorry about that error.

crazykid
03-24-2010, 03:49 AM
Hm, when I put in a random word like "hello" or "ggfdgfd" into the Email textbox and pres Submit, it resets everything and then when I put in my email and click Submit, the page goes blank.

DJCMBear
03-24-2010, 03:56 AM
Hm, when I put in a random word like "hello" or "ggfdgfd" into the Email textbox and pres Submit, it resets everything and then when I put in my email and click Submit, the page goes blank.

try this:


<? include "/home1/sparkonl/public_html/fiesta/questdb/core_quest_functions.php";
?>

<?
$quest_category = $_POST['Category'];
$quest_email=$_POST['Email'];
$quest_name = $_POST['Name'];
$quest_level = $_POST['Level'];
$quest_location = $_POST['Location'];
$quest_npc = $_POST['NPC'];
$quest_objective = $_POST['Objective'];
$quest_procedure = $_POST['Procedure'];
$quest_rewards = $_POST['Rewards'];
$quest_pre = $_POST['Prereq'];
$quest_repeatable = $_POST['Repeatable'];
$quest_ipaddress=$_SERVER['IPAddress'];
$error = '0';
//If they are all blank we just say to compose a message
if(!$quest_category AND !$quest_name)
{
?>
<p><b><center>Please complete the quest information<center></b></p>
<br>
<?
}

//Since this form was partially filled out we need to return an error message
else
{
//If the variable error is not set to zero, we have a problem and should show the error message
if (!$quest_name)
{
$error = 'You must enter the quests name';
}
if (!$quest_email)
{
$error = 'You must enter your email address';
}
if($error != '0')
{
echo "<p>$error</p><br>";
}

//There are no errors so far which means the form is completely filled out
else
{
$category_check = $quest_category;
if($category_check > '0')
{
if ($quest_category = 1) {
$category_name ="quest1-10.php";
}
elseif ($quest_category = 2) {
$category_name ="quest11-20.php";
}
elseif ($quest_category = 3) {
$category_name ="quest21-30.php";
}
elseif ($quest_category = 4) {
$category_name ="quest31-40.php";
}
elseif ($quest_category = 5) {
$category_name ="quest41-50.php";
}
elseif ($quest_category = 6) {
$category_name ="quest51-60.php";
}
elseif ($quest_category = 7) {
$category_name ="quest61-70.php";
}
elseif ($quest_category = 8) {
$category_name ="quest71-80.php";
}
elseif ($quest_category = 9) {
$category_name ="quest81-90.php";
}
elseif ($quest_category = 10) {
$category_name ="quest91-100.php";
}
elseif ($quest_category = 11) {
$category_name ="quest100+.php";
}
elseif ($quest_category = 12) {
$category_name ="questkq.php";
}
else {
echo ERROR;
}

$link_name = str_replace(" ", "_", "$quest_name");
$quest_link = "http://fiestavault.sparkonline.net/quest/$category_name#$link_name";
mysql_query("INSERT INTO master (Name, Link, Namelink) VALUES('$quest_name', '$quest_link', '$link_name')") or die (mysql_error());

//Let the user know everything went ok.
echo "<center><p><b>You have successfully submitted an quest!</b></p></center><br>";
}
//Since they are trying to send messages faster than every 15 seconds, give them an error message
}
//If they mis spelled or, made up a username, then give an error message telling them its wrong.
}

//Since we may have set the error variable to something while trying to send the message, we need another error check
if($error != '0')
{
echo "<p>$error</p><br>";
}else{
//Here's the form for the input
?>
<?php
if(isset($quest_email) && eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $quest_email)) {
mysql_query("INSERT INTO quest (Category, Name, Level, Location, NPC, Objective, `Procedure`, Rewards, Prereq, Repeatable, Email, IPAddress) VALUES('$quest_category', '$quest_name', '$quest_level', '$quest_location', '$quest_npc', '$quest_objective', '$quest_procedure', '$quest_rewards', '$quest_pre', '$quest_repeatable', '$quest_email', '$quest_ipaddress')") or die (mysql_error());
}
?>
<center>
<form name="send" method="post" action="submitquest.php">
<table width="100%">
<tr>
<td width="150px" align="center" valign="top"><p><b>Quest Category</b></p> <SELECT NAME="Category">
<OPTION VALUE="">Select a category</OPTION>
<OPTION VALUE=""></OPTION>
<OPTION VALUE="1">Level 1-10</OPTION>
<OPTION VALUE="2">Level 11-20</OPTION>
<OPTION VALUE="3">Level 21-30</OPTION>
<OPTION VALUE="4">Level 31-40</OPTION>
<OPTION VALUE="5">Level 41-50</OPTION>
<OPTION VALUE="6">Level 51-60</OPTION>
<OPTION VALUE="7">Level 61-70</OPTION>
<OPTION VALUE="8">Level 71-80</OPTION>
<OPTION VALUE="9">Level 81-90</OPTION>
<OPTION VALUE="10">Level 90-100</OPTION>
<OPTION VALUE="11">Level 100+</OPTION>
<OPTION VALUE="12">Kingdom Quest</OPTION>
</SELECT></td></tr>
<tr><td>
<center><b>Quest Information</b></center>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="50%" align="left" valign="top"><p>Quest Name: <input type="text" name="Name" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting Level: <input type="text" name="Level" value="" size="5" maxlength="5"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Starting Location: <input type="text" name="Location" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting NPC: <input type="text" name="NPC" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Objective:<textarea name="Objective" type="text" id="Objective" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Procedure:<textarea name="Procedure" type="text" id="Procedure" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Rewards:<textarea name="Rewards" type="text" id="Rewards" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Pre-Requisites:<input type="text" name="Pre" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="100%" align="left" valign="top">Repeatable: No<input type="RADIO" name="Repeatable" value="No" checked> Yes<input type="RADIO" name="Repeatable" value="Yes"></td>
</tr>
<tr>
<td width="100%" align="right" valign="top">Email:<input type="text" name="Email" value="" size="20" maxlength="255"></td>
</tr>
<tr>
<td><input type="reset" value="Reset" /></td>
<td><input type="submit" name="Submit" value="Submit quest"></td>
</tr>
</table>
</form>
</center>
<? } ?>

crazykid
03-24-2010, 04:13 AM
Great, it works! But now I'm curious to know why does the form reset itself if you type in some random letters in the Email input textbox?

DJCMBear
03-24-2010, 04:48 AM
Great, it works! But now I'm curious to know why does the form reset itself if you type in some random letters in the Email input textbox?

because its not a vaild email if it doesnt have an '@' symbol, but what that email validater does aswell is checks to see if the email contains a . for the .com or .co.uk etc.

starvos
03-24-2010, 04:59 AM
Isn't it better to verify the email using a javascript?

DJCMBear
03-24-2010, 05:01 AM
Isn't it better to verify the email using a javascript?

it would be easier yes but anyone can change javascripts in their own url where as php is server side and users cant get to the validator.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum