Validating Email Address and Redirecting
01-21-2009, 02:31 PM
|
Validating Email Address and Redirecting
|
Posts: 674
Name: James
Location: KENT
|
Hi all,
I need to some how validate a email address to see if they have taken a survey what is the best way to do this ?
also is there a way to redirect sumone to another location for example
if they completed the survery load this page
else
you didnt do somthing ...
|
|
|
|
01-21-2009, 02:45 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 996
Location: Not positive
|
You mean something like this? Using php, naturally.
PHP Code:
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { echo "Email address accepted."; } else { echo "Go back and rewrite that, spammer!"; }
- Steve
|
|
|
|
01-21-2009, 03:03 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 674
Name: James
Location: KENT
|
Hi thanks but I mean more of a loop that loop thought the usernam in the database to see if the email was already in there
|
|
|
|
01-21-2009, 03:08 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 2,787
Name: Matt
Location: Irvine, CA
|
PHP Code:
$query = "SELECT COUNT(*) FROM `table` WHERE `email` = '$email'";
$result = mysql_query($query);
$count = mysql_fetch_array($result, MYSQL_NUM);
if($count[0] < 1)
{
//email does not exist in database
}
|
|
|
|
01-21-2009, 03:45 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 674
Name: James
Location: KENT
|
Hi I have tried that but now for some reason it wont submit the data to my database I cant see why
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Handel Form</title>
</head>
<body>
<?php
$connection = mysql_connect('host','usernam','pass')or die(mysql_error());
if($connection===FALSE){
echo mysql_error();
die();
}
if(mysql_select_db('m08jpr23', $connection)===FALSE){
echo mysql_error();
die();
}
if (!empty($_REQUEST['Email'])){
$Email = $_REQUEST['Email'];
$query = "SELECT COUNT(*) FROM `Survey` WHERE `email` = '$email'";
$result = mysql_query($query);
$count = mysql_fetch_array($result, MYSQL_NUM);
if($count[0] < 1)
{
$Movies1 = $_REQUEST['Movies1'];
$Score1 = $_REQUEST['Score1'];
$Score2 = $_REQUEST['Score2'];
$Score3 = $_REQUEST['Score3'];
$Score4 = $_REQUEST['Score4'];
$Movies2 = $_REQUEST['Movies2'];
$Score5 = $_REQUEST['Score5'];
$Score6 = $_REQUEST['Score6'];
$Score7 = $_REQUEST['Score7'];
$Score8 = $_REQUEST['Score8'];
$Movies3 = $_REQUEST['Movies3'];
$Score9 = $_REQUEST['Score9'];
$Score10 = $_REQUEST['Score10'];
$Score11 = $_REQUEST['Score11'];
$Score12 = $_REQUEST['Score12'];
$Movies4 = $_REQUEST['Movies4'];
$Score13 = $_REQUEST['Score13'];
$Score14 = $_REQUEST['Score14'];
$Score15 = $_REQUEST['Score15'];
$Score16 = $_REQUEST['Score16'];
$Movies5 = $_REQUEST['Movies5'];
$Score17 = $_REQUEST['Score17'];
$Score18 = $_REQUEST['Score18'];
$Score19 = $_REQUEST['Score19'];
$Score20 = $_REQUEST['Score20'];
$query1 = "INSERT INTO Survey (Email, Movies, Score, Score1, Score2, Score3) VALUES ('$Email','$Movies1','$Score1','$Score2','$Score3','$Score4'),('$Email','$Movies2','$Score5','$Score6','$Score7','$Score8'),('$Email','$Movies3','$Score9','$Score10','$Score11','$Score12'),('$Email','$Movies4','$Score13','$Score14','$Score15','$Score16'),('$Email','$Movies5','$Score17','$Score18','$Score19','$Score20')";
echo 'Thank you for taking the survey your discount is Awesome01';
}
else{
echo "you have already taken the survey you can only take it once";
}
if($ret===FALSE){
echo 'failure to submit data<br/>';
echo mysql_error();
}
else{
mysql_close($connection);
}
} else {
$Email = NULL;
echo '<p class="error"> You forgot to enter a Email!</p>';
}
?>
</body>
</html>
also is there a way to send a user to another page so instead of it saying you forgot to enter a email address i can send them to a page ?
|
|
|
|
01-21-2009, 04:01 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 2,787
Name: Matt
Location: Irvine, CA
|
Well from your code it looks like you initialize query1 but never actually execute it.
PHP Code:
mysql_query($query1);
And yes there is a way to send a user to another page.
PHP Code:
header('Location: myLocation.php');
You can use a relative path or a url, but you cannot use the header function if the headers are already sent, which will be the case if you use echo before header.
|
|
|
|
01-21-2009, 04:08 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 674
Name: James
Location: KENT
|
does it matter where i execute it ? and can the header be put anywhere in the script ? thanks for ya help so far
|
|
|
|
01-21-2009, 04:52 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 2,787
Name: Matt
Location: Irvine, CA
|
You have to execute it sometime after query1 is initialized, add the line of code I gave you above right after you set query1.
Call header(Location: ) when you want the user to be forwarded to a new page. Just make sure that at that point you haven't called echo or print or anything that would send headers.
|
|
|
|
01-21-2009, 05:13 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 674
Name: James
Location: KENT
|
Thanks sorted   can I ask one more things?
I have table that as an id,email,movie,score,score1,score2,score3 now I have to sort these in order of movie add the values up then display the result on web page
How could I do this I am gussing I would need to select the fields I want like
select movie,score,score1,score2,score3 from Survey order by Movies
just not sure how to do the calculations..
Thanks
|
|
|
|
01-21-2009, 06:02 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 2,787
Name: Matt
Location: Irvine, CA
|
Are you trying to get the sum of all of the scores?
Code:
SELECT SUM(score, score1, score2, score3) FROM `Survey` ORDER BY `movie`
Or are you trying to order your result by the sum of the scores?
Code:
SELECT `movie` FROM `Survey` ORDER BY SUM(score, score1, score2, score3)
Sorry if I'm not understanding the question
|
|
|
|
01-21-2009, 06:11 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 674
Name: James
Location: KENT
|
its ok let me try explain it bit better I have a survey and let say the result from this were
Bad Boys 4 4 5 8
Indian Jones TOD 4 6 5 5
Green Street 4 6 5 7
Cape Fear 4 3 8 9
Jackass 4 5 6 6
Bad Boys 4 4 5 8
Indian Jones TOD 4 6 5 5
Green Street 4 6 5 7
Cape Fear 4 3 8 9
Jackass 4 5 6 6
I then want it to sort them in order of movies so all the bad boys movies are together all the jackass ones are togehter so on then I need to count the score from each one and display the result .
so for example it say bad boys then have total result of all the badboys values together. hope that is abit better
|
|
|
|
01-21-2009, 06:35 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 2,787
Name: Matt
Location: Irvine, CA
|
PHP Code:
$query = 'SELECT movie, SUM(score, score1, score2, score3) FROM Survey ORDER BY movie;';
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_NUM)
{
echo $row[0] . ': ' . $row[1] . '<br />';
}
The code above would display:
Bad Boys: 21
Bad Boys: 21
Cape Fear: 24
Cape Fear: 24
Green Street: 22
Green Street 22
.
.
.
Is that what you are looking for?
|
|
|
|
01-21-2009, 06:42 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 674
Name: James
Location: KENT
|
kinder I would like it to display bad boys once with the score of both bad boys broken down so you would have for example
Example Result from survey
movie |Score |score1 |Score2 |score3
Badboys 4 4 5 8
Badboys 4 4 5 8
and the final result would after the calculation
movie |Score |score1 |Score2 |score3
Badboys 8 8 10 16
hope that makes sense thanks for all your time :P
|
|
|
|
01-21-2009, 07:48 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 2,787
Name: Matt
Location: Irvine, CA
|
SELECT movie, SUM(score), SUM(score1), SUM(score2), SUM(score3) FROM survey GROUP BY movie
I think that should do it.
|
|
|
|
01-21-2009, 07:57 PM
|
Re: Validating Email Address and Redirecting
|
Posts: 674
Name: James
Location: KENT
|
thanks I'll try that 2morrow thanks for all ya help you have been amazing 
|
|
|
|
|
« Reply to Validating Email Address and Redirecting
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|