Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Validating Email Address and Redirecting
Old 01-21-2009, 02:31 PM Validating Email Address and Redirecting
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
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 ...
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
 
Register now for full access!
Old 01-21-2009, 02:45 PM Re: Validating Email Address and Redirecting
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
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
stevej is offline
Reply With Quote
View Public Profile
 
Old 01-21-2009, 03:03 PM Re: Validating Email Address and Redirecting
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
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
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 01-21-2009, 03:08 PM Re: Validating Email Address and Redirecting
NullPointer's Avatar
Will Code for Food

Posts: 2,787
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
$query "SELECT COUNT(*) FROM `table` WHERE `email` = '$email'";
$result mysql_query($query);
$count mysql_fetch_array($resultMYSQL_NUM);
if(
$count[0] < 1)
{
    
//email does not exist in database

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-21-2009, 03:45 PM Re: Validating Email Address and Redirecting
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
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 ?
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 01-21-2009, 04:01 PM Re: Validating Email Address and Redirecting
NullPointer's Avatar
Will Code for Food

Posts: 2,787
Name: Matt
Location: Irvine, CA
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-21-2009, 04:08 PM Re: Validating Email Address and Redirecting
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
does it matter where i execute it ? and can the header be put anywhere in the script ? thanks for ya help so far
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 01-21-2009, 04:52 PM Re: Validating Email Address and Redirecting
NullPointer's Avatar
Will Code for Food

Posts: 2,787
Name: Matt
Location: Irvine, CA
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-21-2009, 05:13 PM Re: Validating Email Address and Redirecting
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
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
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 01-21-2009, 06:02 PM Re: Validating Email Address and Redirecting
NullPointer's Avatar
Will Code for Food

Posts: 2,787
Name: Matt
Location: Irvine, CA
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-21-2009, 06:11 PM Re: Validating Email Address and Redirecting
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
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
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 01-21-2009, 06:35 PM Re: Validating Email Address and Redirecting
NullPointer's Avatar
Will Code for Food

Posts: 2,787
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
$query 'SELECT movie, SUM(score, score1, score2, score3) FROM Survey ORDER BY movie;';
$result mysql_query($query);
while(
$row mysql_fetch_array($resultMYSQL_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?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-21-2009, 06:42 PM Re: Validating Email Address and Redirecting
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
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
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 01-21-2009, 07:48 PM Re: Validating Email Address and Redirecting
NullPointer's Avatar
Will Code for Food

Posts: 2,787
Name: Matt
Location: Irvine, CA
Trades: 0
SELECT movie, SUM(score), SUM(score1), SUM(score2), SUM(score3) FROM survey GROUP BY movie

I think that should do it.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-21-2009, 07:57 PM Re: Validating Email Address and Redirecting
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
thanks I'll try that 2morrow thanks for all ya help you have been amazing
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Reply     « Reply to Validating Email Address and Redirecting
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.48295 seconds with 12 queries