runnerjp Posted May 9, 2008 Share Posted May 9, 2008 hey guys... ok in my registor script i would like to display an error message if the data is not right so for example my 3 points are <?<?php session_start(); //allows session include "config.php"; echo "<center>"; //checks if there trying to veriy there account if(isset($_GET['verify'])) { //gets the code and makes it safe $code = addslashes($_GET['code']); //gets the code from the database $getcode=mysql_query("SELECT * FROM `verification` WHERE `code` = '$code'"); //counts the number of rows $getcode = mysql_num_rows($getcode); //if the ammount of rows is 0 the code does not exist if($getcode == 0) { echo "Invalid verification code!"; } //or if the code does exist we will activiate there account else{ //get the data from the database $getcode=mysql_query("SELECT * FROM `verification` WHERE `code` = '$code'"); //fetchs the data from the db $dat = mysql_fetch_array($getcode); //sets the users user level to 2 which means they can now use there account $update = mysql_query("UPDATE `members` SET `userlevel` = '2' WHERE `username` = '".$dat['username']."'") or die(mysql_error()); //deletes the code as there is no use of it now $delete = mysql_query("DELETE FROM `verification` WHERE code = '$code'"); //says thanks and your account is ready for use $msg='Thank you, Your account has been verified.'; } }else //if we have posted the register for we will register this user if(isset($_GET['register'])) { //check to see if any fields were left blank if((!$_POST[username]) || (!$_POST[password]) || (!$_POST[cpassword]) || (!$_POST[email])) { error='A field was left blank please go back and try again.'; }else{ //posts all the data from the register form $username = $_POST[username]; $password = $_POST[password]; $cpassword = $_POST[cpassword]; $email = $_POST[email]; //check see if the 2 passwords are the same if($password == $cpassword) { //encrypts the password 8 times $password = sha1(md5(md5(sha1(md5(sha1(sha1(md5($password)))))))); $cname = mysql_query("SELECT `username` FROM `members` WHERE `username` = '$username'"); $cname= mysql_num_rows($cname); //checks to see if the username or email allready exist if($cname>=1) { error= 'The username is already in use'; }else{ //gets rid of bad stuff from there username and email $username = addslashes(htmlspecialchars($username)); $email = addslashes(htmlspecialchars($email)); if($semail == "1") { // $email set as 1 means email activation is active //adds them to the db $adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`) VALUES('$username','$password','$email')"); //posible letters for the verification code $alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; //shuffles the letters around to create a 16 long code $code = substr(str_shuffle($alphanum), 0, 16); //adds there code along with there user name to the db $addcode = mysql_query("INSERT INTO `verification` (`username`, `code`) VALUES('$username','$code')"); //don't edit this, this is the link for there activication $link = "http://$host$self?verify&code=$code"; //sends the email to the person mail("$email", "Member-Ship Validation", "Thank you for registering on $sitename. Please copy the below link into you address bar, $link", "From: Site Verification"); //message sent now lets tell them to check there email echo "You are now registered,<br><br>Please check your email to activate your account."; }else{ //no need for email activation $adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`, `userlevel`) VALUES('$username','$password','$email','2')"); message= 'You are now registered,<br><br>You can now loggin to your account'; } } }else{ error='Your password and conformation password do not match!'; with them apearing like so <?php if (isset ( $error)) echo '<p class="error">' . $error . '</p>' . "\n"; if (isset ($msg)) echo '<p class="msg">' . $msg . '</p>' . "\n"; else //if we have a mesage we don't need this form again. if (!isset($error) && !isset($msg)) echo 'Please fill in all fields correctly!'; ?>[code] so to recap they are if((!$_POST[username]) || (!$_POST[password]) || (!$_POST[cpassword]) || (!$_POST[email])) { error='A field was left blank please go back and try again.'; if($cname>=1) { error= 'The username is already in use'; $adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`, `userlevel`) VALUES('$username','$password','$email','2')"); message= 'You are now registered,<br><br>You can now loggin to your account'; } } }else{ error='Your password and conformation password do not match!'; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/104899-solved-creating-an-error-message/ Share on other sites More sharing options...
BlueSkyIS Posted May 9, 2008 Share Posted May 9, 2008 looks like you got it figured out. Quote Link to comment https://forums.phpfreaks.com/topic/104899-solved-creating-an-error-message/#findComment-536876 Share on other sites More sharing options...
runnerjp Posted May 9, 2008 Author Share Posted May 9, 2008 woops sorry i shud tell you my error message... i get Parse error: syntax error, unexpected '=' in /home/runningp/public_html/register.php on line 35 Quote Link to comment https://forums.phpfreaks.com/topic/104899-solved-creating-an-error-message/#findComment-536885 Share on other sites More sharing options...
BlueSkyIS Posted May 9, 2008 Share Posted May 9, 2008 hm, which line is 35? Quote Link to comment https://forums.phpfreaks.com/topic/104899-solved-creating-an-error-message/#findComment-536889 Share on other sites More sharing options...
runnerjp Posted May 9, 2008 Author Share Posted May 9, 2008 error='A field was left blank please go back and try again.'; Quote Link to comment https://forums.phpfreaks.com/topic/104899-solved-creating-an-error-message/#findComment-536899 Share on other sites More sharing options...
947740 Posted May 9, 2008 Share Posted May 9, 2008 What exactly are you doing there? Is that supposed to be a variable? If it is, it should be $error. Quote Link to comment https://forums.phpfreaks.com/topic/104899-solved-creating-an-error-message/#findComment-536921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.