Forum Moderators: coopster

Message Too Old, No Replies

using mySQL to limit html form submissions

         

onawire

10:28 pm on Jul 19, 2010 (gmt 0)

10+ Year Member



Here is my senerio.

I run a contest that has an html entryform that needs to be filled out to enter. I only want a person to be able to send this entryform 1 time per day!

The html form is validated on the client side with javascript to make sure all required fields are filled in. then action="my.php file".

my php file connects to mysql database where the information is stored with an ID number and Timestamp (w/ date).

ID, FNAME, LNAME, EMAIL, ETC.. is entered into my database

First Question: could you point me in the direction for a good server side validation tutorial.

Second Question:

I want them to be able to submit the entry form 1 time per day...how do i control this? I thought about doing cookies but if multiple ppl share computers this would cause a problem.

My thought: is to control it by their email address, maybe?

have it check my database for their last submission by their email address and look at the timestamp of that submission - if the difference btw the current time/date and the last submission is less than 24 hrs or (idealy the date is the same, i want per day not per 24 hrs) then it could stop the submission and give an error message?

is this possible? is this a good idea? is there a better way?

my experience is html, css...i've just got into javascript, php, cgi, perl, etc... so i don't know what is possible and what isn't.

if you know of any tutorials or something that would be great

also, i know all of this could just be ruined if they create fake email address...this would allow them to enter many many times....im working on creating a members only area to only allow members with real email addresses to enter...

any help would be appreciated.

if i should post this under a different topic please let me know. or if i should post any code or a better explanation.

thanks,
paul

impact

12:42 am on Jul 20, 2010 (gmt 0)

10+ Year Member



Hello,

Well there are many server side scripts available on google. What you have to do is to narrow down your objective and search. Example: if you search 'server side validation' you may get unexpected results while if you search 'how to query mysql and php' or 'php login script', will give lots of good search results.

The kind of issue that you are having, in my opinion, your idea about storing DATE in mysql is the best option.

Hope this helps.

onawire

12:57 am on Jul 22, 2010 (gmt 0)

10+ Year Member



i figured out how to do what i wanted to do...but know i have a new problem

i need to search the database for the email but i want it to be case INsensitive.

if the same email but with a capital letter ...the search reads two different email addys.

here is my php file.

<?php

if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "ERROR: You need to submit the form - You do not have permission from WBSnightout.com to see this page!";
exit;
}

//Set variables
$FNAME = $_POST['FNAME'];
$LNAME = $_POST['LNAME'];
$LOCATION = $_POST['LOCATION'];
$PHONE = $_POST['PHONE'];
$EMAIL = $_POST['EMAIL'];
$TRACKING = $_POST['TRACKING'];
$NEWSLETTER = $_POST['NEWSLETTER'];
$ANSWER = $_POST['ANSWER'];
$CONTEST = $_POST['CONTEST'];
$HELPFUL = $_POST['HELPFUL'];
$COMMENTS = $_POST['COMMENTS'];
$TERMS = $_POST['terms'];
$nowdate = date("Y-m-d");


//Validate first
if(empty($FNAME)||empty($LNAME))
{
echo "Full Name is Manditory!";
exit;
}

if(empty($LOCATION))
{
echo "Location is Manditory!";
exit;
}

if(empty($PHONE))
{
echo "Phone Number is Manditory!";
exit;
}

if(empty($TRACKING))
{
echo "Phone Number is Manditory!";
exit;
}

if(empty($EMAIL))
{
echo "Email is Manditory!";
exit;
}

//make connection
mysql_connect ("localhost", "username", "pword") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("sql_db");

// Get a specific result from the database_table
$result = mysql_query("SELECT * FROM BEAUTYGIVEAWAY
WHERE EMAIL='$EMAIL'") or die(mysql_error());

// get the first and loop until all entries are found with the above result
while($row = mysql_fetch_array($result))
// compare the entry from the form to the result of the sql_table & the date of entry into table
if($EMAIL == $row['EMAIL'] && $nowdate == $row['DATETIME'])
{
header('Location: /contest_alert/index.html');
exit;
}
// if no entry that day - insert into sql_table
$query="INSERT INTO BEAUTYGIVEAWAY (ID, DATETIME, FNAME, LNAME, LOCATION, PHONE, EMAIL, TRACKING, NEWSLETTER, ANSWER, FAVBEAUTY, CONTEST_SUG, HELPFUL, COMMENTS, TERMS)VALUES ('NULL', '$nowdate', '$FNAME', '$LNAME', '$LOCATION', '$PHONE', '$EMAIL', '$TRACKING', '$NEWSLETTER', '$ANSWER', '$FAVBEAUTY', '$CONTEST_SUG', '$HELPFUL', '$COMMENTS', '$TERMS')";

mysql_query($query) or die ('Error updating database');

// Start the email
$email_from = 'email@email.com;//<== update the email address
$email_subject = "THIS IS JUST A TEST";
$email_body = "A new Entry for the Cosmetologist Contest has been receieved by the Database. \n".
"The entry has been sent by: \n".
" \n".
"Name: $FNAME $LNAME \n".
"Phone: $PHONE \n".
" \n".
" \n".
" \n".

$to = "email@email.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: /contestty/index.html');



?>


thanks,
paul

coopster

1:05 am on Jul 22, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



but i want it to be case INsensitive.


See if this MySQL page helps ...
Case Sensitivity in String Searches [dev.mysql.com]

onawire

7:57 pm on Jul 22, 2010 (gmt 0)

10+ Year Member



i figured it out.

new variable

$email_lc = strtolower

had it INSERT as lower case and SELECT from lower case.

onawire

7:58 pm on Jul 22, 2010 (gmt 0)

10+ Year Member



sorry (edit above)

$email_lc = strtolower($EMAIL)