XIII
Sep 7 2006, 07:43 AM
I just coded this e-mail list, it works well for entering data into database, but if user leaves the field blank or adds an already exist e-mail it gives him the error message and stops loading the rest of the page.
CODE <?php // Connects to your Database mysql_connect("localhost", "my_username", "mypassword") or die(mysql_error()); mysql_select_db("Database name") or die(mysql_error());
//This code runs if the form has been submitted if (isset($_POST['submit'])) {
//This makes sure they did not leave any fields blank if (!$_POST['email']) {die('<font color=red><b><i>No e-mail added</i></b>'); }
// checks if that e-mail is in use if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $mailcheck = $_POST['email']; $check = mysql_query("SELECT email FROM maillist WHERE email = '$mailcheck'") or die(mysql_error()); $check2 = mysql_num_rows($check);
//if e-mail exists it gives an error if ($check2 != 0) { die('<font color=red><b><i>Already subscribed</i></b>'); } else { echo"<font color=blue><b><i>Subscribed successfully</i></b>"; }
// now we insert it into the database $insert = "INSERT INTO maillist (id, email) VALUES ('0', '".$_POST['email']."')"; $add_email = mysql_query($insert); ?>
<?php } else { ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr bgcolor="#6652D8"> <td width="140"><span class="style1"><span class="style1">Get our Newsletter</span>: </span></td> </tr> <tr><td> <input type="text" name="email" maxlength="100"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Subscribe"></th></tr> <tr><td></td></tr> <tr><td bgcolor="#6652D8"></td> </tr> </table> </form>
<?php } ?>
1- i need to make it say the error message and continue loading the rest of the page. 2- checks for the entered text "if it's a valid e-mail format xxxxxx@xxxx.xxxx."
Comment/Reply (w/o sign-up)
Hercco
Sep 7 2006, 08:38 AM
QUOTE(XIII @ Sep 7 2006, 10:43 AM)  1- i need to make it say the error message and continue loading the rest of the page.
Don't use the die() function then. It does exactly what the name suggest: makes the script commit suicide and print out the error message you specified as it's last words. Simply print out the error in a conventional way ( echo, printf) and make the script not to perform the other subscription steps (such as adding the email to the database). QUOTE(XIII @ Sep 7 2006, 10:43 AM)  2- checks for the entered text "if it's a valid e-mail format xxxxxx@xxxx.xxxx."[/color]
For that you need to use a regular expression. There's thousands of examples available online. Here's one thread about the subject: http://www.astahost.com/index.php?showtopic=1588
Comment/Reply (w/o sign-up)
XIII
Sep 7 2006, 10:40 AM
QUOTE(Hercco @ Sep 7 2006, 05:38 PM)  Don't use the die() function then. It does exactly what the name suggest: makes the script commit suicide and print out the error message you specified as it's last words. Simply print out the error in a conventional way ( echo, printf) and make the script not to perform the other subscription steps (such as adding the email to the database).
That's already what i need, i can't get a function to do that, i need a function to show the error message and stop loading the script while loading the rest of the page.
QUOTE For that you need to use a regular expression. There's thousands of examples available online. Here's one thread about the subject: http://www.astahost.com/index.php?showtopic=1588
Thank you so much, this link helped me so much, specially Houdini's post, he is really a php guru.
Comment/Reply (w/o sign-up)
TavoxPeru
Sep 9 2006, 10:46 PM
I hope that the following code help you, is a registration and activation page, its very simple and self explanatory, if you dont understand something please send me a PM. CODE <?php /** * Generate an activation code * @param int $length is the length of the activation code to generate * @return string */ function generateCode($length = 10) { $password=""; $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; srand((double)microtime()*1000000); for ($i=0; $i<$length; $i++) { $password .= substr ($chars, rand() % strlen($chars), 1); } return $password; }
// config file with database info (db, host, user, password) and connection functions. require("config.php"); ?> <HTML> <HEAD> <TITLE>Registration www.gigasoft.astahost.com</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <style type="text/css"> body { background-color:#131313; font-family:Verdana, Arial; font-weight:bold; font-size:9px; color:#FFFFFF; } .register_box { border: 1px solid #323232; background-color: #202020; font-family: Verdana, Arial; font-weight: bold; font-size: 9px; color: #FFFFFF; } </style> </head> <body> <?php $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : "new"; switch($action) { //-------------------------------------- // [New Registration] //-------------------------------------- case "new": if(!isset($_POST['register'])) { echo " <form action='registration.php' method='POST'> Name: <br /> <input type='text' name='name' class='register_box'> <br /> Email: <br /> <input type='text' name='email' class='register_box'> <br /> Nickname: <br /> <input type='text' name='nickname' class='register_box'> <br /> Password: <br /> <input type='password' name='password' class='register_box'> <br /> <input type='submit' name='register' value='New Registration!' class='register_box'> <input type='hidden' name='action' value='new'> </form>"; } elseif(isset($_POST['register'])) { $name = mysql_real_escape_string($_POST['name']); $email = mysql_real_escape_string($_POST['email']); $nickname = mysql_real_escape_string ($_POST['nickname']); $password = mysql_real_escape_string($_POST['password']); $activation_code = generateCode(25); $nameq = "SELECT name FROM registration WHERE name = '$name'"; $emailq = "SELECT email FROM registration WHERE email = '$email'"; $nickq = "SELECT nickname FROM registration WHERE nickname = '$nickname'"; //put errors into an array I need to change these if I change the db $errors = array(); if(empty($name)) { $errors[] = "The name field was blank! <br />"; }
$reg=mysql_query($nameq) or die(mysql_error()); if(mysql_num_rows($reg) > 0) { $errors[] = "The name given is already in use! Please try another one! <br />"; }
if(empty($email)) { $errors[] = "The email field was blank! <br />"; }
$reg=mysql_query($emailq) or die(mysql_error()); if(mysql_num_rows($reg) > 0) { $errors[] = "The email given is already in use! Please try another one! <br />"; }
if(empty($nickname)) { $errors[] = "The nickname field was blank! <br />"; }
$reg=mysql_query($nickq) or die(mysql_error()); if(mysql_num_rows($reg)>0) { $error[] = "That nickname is already taken. Please try another one.<br />"; }
if(empty($password)) { $errors[] = "The password field was blank! <br />"; } if(count($errors) > 0) { foreach($errors as $err) { echo $err; } } else { $sqlq = "INSERT INTO registration (name, email, nickname, password, is_activated, activation_code)"; $sqlq .= " VALUES ('$name', '$email', '$nickname', '".md5($password)."', '0', '$activation_code')"; mysql_query($sqlq) or die(mysql_error()); echo "Thanks for registering! You will recieve an email shortly containing your validation code, and a link to activate your account!"; mail($email, "New Registration, www.gigasoft.astahost.com", "Thanks for registering on TRIVIA at GIGASOFT.\n\nHere are your login details:\n\nNickname: ".$nickname."\n\nPassword: ".$password."\n\nIn order to login and gain full access, you must validate your account.\n\nClick here to validate:\n\nhttp://www.gigasoft.astahost.com/trivia/registration.php?action=activate&nickname=".$nickname."&code=".$activation_code."\n\nThanks!\n\n[TavoXPerU]"); } } break; case "activate": //-------------------------------------- // [Activate Account] //-------------------------------------- if(isset($_GET['nickname']) && isset($_GET['code'])) { $nickname = mysql_real_escape_string($_GET['nickname']);
if(mysql_num_rows(mysql_query("SELECT email FROM registration WHERE nickname = '$nickname'")) == 0) { echo "That username is not in the database!"; } else { $activate_query = "SELECT is_activated FROM registration WHERE nickname = '$nickname'"; $is_already_activated = mysql_fetch_object(mysql_query($activate_query)) or die(mysql_error());
if($is_already_activated->is_activated == '1') { echo "This user is already activated!"; } else { $code = mysql_real_escape_string($_GET['code']); $code_query = "SELECT activation_code FROM registration WHERE nickname = '$nickname' LIMIT 1"; $check_code = mysql_fetch_object(mysql_query($code_query)) or die(mysql_error());
if($code == $check_code->activation_code) { $update = "UPDATE registration SET is_activated='1', regdate=NOW(), last_login=NOW() WHERE nickname = '$nickname'"; mysql_query($update) or die(mysql_error()); echo "User $nickname has been activated! Thanks!"; echo "<br />Please <a href=\"login.php\">Click here to Login</a> and enter the site."; } else { echo "The activation code was wrong! Please try again!"; } } } } else { echo "No ID or user given to activate!"; } break; } ?> </body> </html>
Best regards,
Comment/Reply (w/o sign-up)
XIII
Sep 11 2006, 02:14 AM
Thank you so much, i respect your effort to paste this registeration system here though in fact i do need only to fix some problems in my own script, i already fixed some of them, so i will paste the new edited code, i hope to find some help fixing the rest of my code errors:
CODE <?php /// Connects to your Database mysql_connect("localhost", "my username", "my password") or die(mysql_error()); mysql_select_db("my db name") or die(mysql_error());
///This code runs if the form has been submitted if (isset($_POST['submit'])) {
///This makes sure they did not leave any fields blank if (!$_POST['email']) { [COLOR=Red]die[/COLOR]"<font color=red><b><i>No e-mail added</i></b>"; }
/// checks if that e-mail is in use if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $mailcheck = $_POST['email']; $check = mysql_query("SELECT email FROM maillist WHERE email = '$mailcheck'") or die(mysql_error()); $check2 = mysql_num_rows($check);
///if e-mail exists it gives an error if ($check2 != 0) { echo"<font color=red><b><i>Already subscribed</i></b>"; } else { $insert = "INSERT INTO maillist (id, email) VALUES ('0', '".$_POST['email']."')"; $add_email = mysql_query($insert); echo"<font color=blue><b><i>Subscribed successfully</i></b>"; }
///now we insert it into the database
?>
<?php } else { ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr bgcolor="#6652D8"> <td width="140"><span class="style1"><span class="style1">Get our Newsletter</span>: </span></td> </tr> <tr><td> <input type="text" name="email" maxlength="100"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Subscribe"></th></tr> <tr><td></td></tr> <tr><td bgcolor="#6652D8"></td> </tr> </table> </form>
<?php } ?>
still that red die above in the code stop loading of the whole page, and if i use print or echo, it will tell the error message but will not prevent inserting to database, the above red die in :
CODE ///This makes sure they did not leave any fields blank if (!$_POST['email']) { [COLOR=Red]die[/COLOR]"<font color=red><b><i>No e-mail added</i></b>"; }
stops all the page from continue loading, when i used echo instead, it didn't prevent inserting a blank row to database.
the second problem is, i have another form in the same page, when i press submit, it excute both scripts, what should i do?
Comment/Reply (w/o sign-up)
Similar Topics
Keywords : e, mail, list, error
- Php Configuration Error?
(7)
Cant Find The Error
(2) In this code I want to retrieve the energy and max energy of a players account, then add 8% to
energy of maxenergy, hen if energy is bigger than maxenergy, energy is then made equal to maxenergy.
Then the database is updated. I don't understand why it's not working.
$query=mysql_query("SELECT MAX(id) as maxid FROM `accounts` LIMIT 1"); $row =
mysql_fetch_assoc($query); $id = $row ; $query = "SELECT * FROM `accounts`";
$result=mysql_query($query); while ($row=mysql_fetch_assoc($result)) { $energy = $row ; $maxenergy
= $row ; } for($i=1; $i $query = "SELECT....
Php Error-where To Put "?>"
(2) lol....lately i have many problems in writing my scripts and i dont know if i should create post
only for purpose so ppl can help me or should i create many post like i am doing right now...i am
NOT making this to get many credits...i am doing it because i need help and many people here help
me! CODE if ($_GET !='race'){ Who do you wanna race? Derbi Senda 50
Honda NS 50 R Suzuki ZR 50 Yamaha DT 50 MX Aprilia RS 50 - ?
} i have this code...if i put after it i get QUOTE Parse error: syntax....
Warning: Mysql_num_rows()
What is the error :S (1) Hey! I've made a register script.. Some time ago it worked. And I ain't sure if I changed
something since then.. The error I am getting is this: Warning: mysql_num_rows(): supplied argument
is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31 Here is
the code on theese lines: CODE $sqlCheckForDuplicate = "SELECT username FROM user WHERE username
= '". $username ."'"; if( mysql_num_rows( mysql_query(
$sqlCheckForDuplicate ) ) == 0 ) { $sqlRegUser = "INSERT INTO ....
Php Math Error
(4) I cant get php to do simple math. Anyway
I need to run a math problem from the mysql database (dont ask why). So lets say I have an entrie: 5
+5. I get it from my db then eval it but nothing happens? How could I make it so that it runs the 5+
5 rather then just displaying it? Thanks, Sparkx Also: I have no clue if it is just my browser or
what but my post breaks to boarder for some odd reason?....
Unexpected Error
Undefined variable??? (2) Is this script correct? index.php : CODE if (isset($_COOKIE )) $_GET =
$_COOKIE ; else setcookie("disp_name", Anonymous, date()+99); ?>
Display Name - DZN
Dislpay Name: name="name" />
proccess.php : CODE Proccessing Request... Please wait...
setcookie("disp_name", $_GET , date()+99); ?> main.php : CODE function customErr....
Using Php With A Mail Server
(2) We all know you can use PHP with a web server, but can you use it with a mail server? I've made
a personal messenger system, and I was thinking about adding additional functionality in the future,
such as the ability to send mail from it. Then I started thinking, would it be possible to recieve
mail with it? Say, have a PHP script that checked when a message arrived at the server, and when it
does, check for something in the message (e.g. "pmsystem-to: admin") that would tell it to send it
to a certain user, and then have it do the scripts to send a PM. So, is it....
PHP: Need Help Sending Mail Using SMTP
(5) While the mail() function of php is all bout simplicity, it lacks the otherwise necessary
flexibility. How do I send an E-Mail using php through SMTP?....
Error On Submit Page
(10) I am writing a new submit page for one of my sites and am doing a few things to stretch my
experience. I am getting an error (naturally.) Here is part pf the page where the error might be:
CODE //Check to see if the web page called itself if (strtoupper($action) == "CHECK") {
//The web page called itself, so run the error checking code //Declare a variable to
hold the error messages $error = ''; // variable names: name, cat, sub_cat, url,
date, status, email, other, area_code, city $name = $_POST ; $cat = $_P....
Got A Wee Error - Can You Help?
(13) I'm taking a PHP course at college and am working on an assignment. There's no database
involved. I've declared my variables from a submit form on another page, and on the page
I'm working on I'm trying to bring them up in a table. But my start-table command is
outputting an error. Here's the code relating to where the error is: CODE //Get First
Item if (isset($_GET )) { $item_1_product = $_GET ; } else {
$item_1_product = ""; //Default value if data missing } if (isset($_GET ))
{ ....
Php Send Mail Through Smtp
(10) Can anyone here tell me how to send mail through SMTP server with php /mellow.gif"
style="vertical-align:middle" emoid=":mellow:" border="0" alt="mellow.gif" /> I have search in many
source code on web and cant find anything /sad.gif" style="vertical-align:middle" emoid=":("
border="0" alt="sad.gif" />....
Using The Php Mail() Function For Images Or Attachments
Can't find a decent tutorial! (6) I read the one mail() tutorial that was posted in the tutorial section and to my horror found that
he had quoted almost verbatim from the PHP Manual off php.net, and made a comment about it, and also
found that if you were new to PHP or the Manual that it was informative but not indepth enough for
my tastes. This is not a tutorial although with the code that will be posted it might look like
one, that is not its intent or purpose. I have searched and found many so called tutorials about
MIME mail and boundries and all that but basically it either told me to use PHPMai....
Sending Mail To A Mailing List
Possibility of sending a newsletter (12) Task : To send an email to a list of email addresses stored in a database Premise : Page is
written in PHP, with the database as MySQL. The email addresses need to be taken from a column of a
table in the database which is queried with some "WHERE" clause. The email sent to these addresses
is static. Objective : To send a newsletter to the members who have subscribed for the same on a
website. Well, there. I have put it as objectively and as clearly as possible. I have searched
for the keywords "mail" and "PHP" on this section of the forum, and from what I have....
Simple E-mail Validation
check for correct address and syntax (2) Hey , this tutorial will tell you a very simple way to check if email addresses entered are with the
correct syntax. Hope this will help you eliminate jokers. So this script will... (check the
characters, and check if there is a " someone somewhere.extension ". Ok, so firstly we create a
function with all the invalid stuff in it:- CODE function CheckMail($email) { if (eregi("^ ( ?
)*@ ( ? )*\. {2,4}$", $email)) { return true; } else { return false; } } Now, to check an
email you just run the variable with the email in it through the function as follow....
Do You Want A Mail Form In Your Site
(2)
Notice from m^e:
Repeat post. Credits reduced by 5 days. Learn to USE
THE SEARCH BUTTON before you make such posts.
did you want to have in your web site mail form
that allow the user to send mails to anther mail from his mail e.g. the compose in yahoo CODE
from to cc bcc subject
function param($Name) { global
$HTTP_POST_VARS; if(isset($HTTP_POST_VARS )) return($H....
In Php, How To Not Display Mysql Connection Error?
Don't want mysql_connect() message (4) In PHP, if the mysql database server cannot be connected, for example database server is handed or
turned off, an error message will be displayed: Warning: mysql_connect(): Unknown MySQL Server Host
"mysql.example.com" ... My question is how to not display this warning message? or can I customise
the error message? if so, how? Thank you.....
Form Mail Php - Use Php To Send Form Through Email
(8) Just sends all form data to a specified email. Does anyone know a free script that does this?....
Mail() Not Working
(4) I'm trying to use the mail() function in a script. But it doesnt work. It keeps returning false.
It's a premade script The code is: CODE function SendPassword($userName) { global
$db,$db_tables;//config.php // set password for username to a random value // return the new
password or false on failure $new_password = mt_rand(); $qry = "UPDATE $db_tables SET
password=password('$new_password') WHERE user_name='$userName'";
$db->db_query($qry); // send notification email $from = "From: $from_email\r\n";
$msg = "....
Php Problem Error Message
I'm working from a book (9) I get this error message when I try to view a small webpage. QUOTE Parse error: parse error,
unexpected T_STRING, expecting ',' or ';' in
/home/nilsc/public_html/bobs/processorder.php on line 27 Line 27 is in this php part: CODE
echo ' Order processed. '; echo $tireqty. ' tires '; echo $oilqty. '
bottles of oil '; echo $sparkqty. ' spark plugs '; $totalqty = 0;
$totalqty = $tireqty + $oilqty + $spakqty; echo 'Items ordered: ' .$totalqty.' ;
$totalamount = 0.....
How To Set Up Form Mail
(4) I am programming on a web site's contact form page, How can I mail the filled in information of
the client to particular E-mail address? I tried form action="mailto:blah@blah", but it is running
all right on my machine rather that other computer in our LAN. The error message I got is a
connection failure error occurred. I noticed there are some form mail info on line, but I have no
idea to figure out how is that works. Anybody have some experience on that? Thanks!....
PHP paFileDB error
an error relating to admin login (0) does any body know how to over come an error in paFileDB which says Warning: Cannot modify header
information - headers already sent by (output started at
/home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
/home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 36 Warning: Cannot modify
header information - headers already sent by (output started at
/home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
/home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 38 i have downloaded the php
from phparena.net directly. Any hel....
PHP paFileDB error
an error relating to admin login. (2) does any body know how to over come an error in paFileDB which says Warning: Cannot modify header
information - headers already sent by (output started at
/home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
/home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 36 Warning: Cannot modify
header information - headers already sent by (output started at
/home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
/home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 38 i have downloaded the php
from phparena.net directly. Any he....
Looking for e, mail, list, error
|
See Also,
*SIMILAR VIDEOS*
Searching Video's for e, mail, list, error
|
advertisement
|
|