JeanieTallis Posted March 30, 2009 Share Posted March 30, 2009 This is my code <?php session_start(); include('settings.php'); if (isset($_POST['submit'])) { if ( !$_POST['full_name'] || !$_POST['email'] || !$_POST['username'] || !$_POST['password'] || !$_POST['password'] == !$_POST['password_confirmed'] || !$_POST['country'] || !$_POST['user_code']) { $error = 'You did not fill in a required field!'; } if (strcmp(md5($_POST['user_code']),$_SESSION['ckey'])) { $error = 'Invalid code entered. Please enter the correct code as shown in the Image!'; } if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $qry = "SELECT username FROM users WHERE username = '".$_POST['username']."'"; $sqlmembers = mysql_query($qry) or die(mysql_error()); $name_check = mysql_fetch_array ($sqlmembers); $name_checkk = mysql_num_rows ($sqlmembers); if ($name_checkk != 0) { $error ='Sorry, the username: <strong>'.$_POST['username'].'</strong>' . ' is already taken, please pick another one. Click back.'; } if (!preg_match("/.*@.*..*/", $_POST['email']) || preg_match("/(<|>)/", $_POST['email'])) { $error = 'Invalid e-mail address.'; } if ($_POST['password'] != $_POST['password_confirmation']) { $error = 'Passwords did not match.'; } $_POST['username'] = strip_tags($_POST['username']); $_POST['password'] = strip_tags($_POST['password']); $_POST['country'] = strip_tags($_POST['country']); if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); $_POST['password'] = addslashes($_POST['password']); $_POST['email'] = addslashes($_POST['email']); $_POST['country'] = addslashes($_POST['country']); } $date_registered = date('m d, Y'); $md5pass = md5($_POST['passwrd_again']); $activ_code = rand(1000,9999); mysql_query("INSERT INTO users (`username`,`email`,`password`,`country`,`date_registered`,`activation_code`,`full_name`) VALUES ('$_POST[username]','$_POST[email]','$md5pass','$_POST[country]','$date_registered','$activ_code','$_POST[full_name]')") or die(mysql_error()); $message = "Dear $_POST[full_name] \n Thank you for registering an account with MyVee. Here are the login details...\n\n Username: $_POST[username] \n User Email: $_POST[email] \n Password: $_POST[password_confirmation] \n Activation Code: $activ_code \n ____________________________________________ *** ACTIVATION LINK ***** \n Activation Link: http://jeanies-poetry.com/activate.php?usr=$_POST[email]&code=$activ_code \n\n _____________________________________________ Thank you. This is an automated response. PLEASE DO NOT REPLY. "; mail($_POST['email'] , "Account Activation", $message, "From: \"Auto-Response\" <notifications@myvee.co.uk>\r\n" . "X-Mailer: PHP/" . phpversion()); unset($_SESSION['ckey']); echo("Registration Successful! An activation code has been sent to your email address with an activation link..."); exit; } ?> <title>MyVee!</title> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <link href="Style2.css" rel="stylesheet" type="text/css"> <div id="wrapper"> <div id="Layer4"> <div style="color:WHITE;"> <script type="text/javascript"> var d=new Date() var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") document.write(weekday[d.getDay()] + " ") document.write(d.getDate() + ". ") document.write(monthname[d.getMonth()] + " ") document.write(d.getFullYear()) </script> </div></div> <div id="Layer2"> <div id="Layer9">There are some outgoing errors with this form which will be fixed in time. It works though, you can register no problem. Sorry for any inconvenience.</div> <div id="Layer10"> <p>Already got a login? go back to the <a href="index.php">homepage</a> and login! </p> </div> </div> <div id="Layer1"></div> <div id="Layer3"> <div id="log"> <?php if ( isset ( $error ) ) { echo ' <p class="error">' . $error . '</p>' . "\n"; } ?> </div> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']?>"> <input type="hidden" name="_submit_check" value="1"/> <br> Name:<br> <input name="full_name" type="text" id="full_name" value="" size="32"> Ex. John Blooper <p>Email:<br> <input name="email" type="text" id="email" value="" size="32"> Ex. johnB@domain.com<br> <br> <label>Username:<br> <input name="username" type="text" id="username" size="32" maxlength="40"> </label> Ex. JBlooper </p> <p>Password:<br> <input name="password" type="password" id="password" size="32" maxlength="40"> Atleast 5 characters</p> <p>Retype Password:<br> <input name="password_confirmed" type="password" id="password_confirmed" size="32"> </p> <p>Country:<br> <select name="country" id="select8"> <option value="Afghanistan">Afghanistan</option> <option value="Albania">Albania</option> <option value="Algeria">Algeria</option> <option value="Andorra">Andorra</option> <option value="Anguila">Anguila</option> <option value="Antarctica">Antarctica</option> <option value="Antigua and Barbuda">Antigua and Barbuda</option> <option value="Argentina">Argentina</option> <option value="Armenia ">Armenia </option> <option value="Aruba">Aruba</option> <option value="Australia">Australia</option> <option value="Austria">Austria</option> <option value="Azerbaidjan">Azerbaidjan</option> <option value="Bahamas">Bahamas</option> <option value="Bahrain">Bahrain</option> <option value="Bangladesh">Bangladesh</option> <option value="Barbados">Barbados</option> <option value="Belarus">Belarus</option> <option value="Belgium">Belgium</option> <option value="Belize">Belize</option> <option value="Bermuda">Bermuda</option> <option value="Bhutan">Bhutan</option> <option value="Bolivia">Bolivia</option> <option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option> <option value="Brazil">Brazil</option> <option value="Brunei">Brunei</option> <option value="Bulgaria">Bulgaria</option> <option value="Cambodia">Cambodia</option> <option value="Canada">Canada</option> <option value="Cape Verde">Cape Verde</option> <option value="Cayman Islands">Cayman Islands</option> <option value="Chile">Chile</option> <option value="China">China</option> <option value="Christmans Islands">Christmans Islands</option> <option value="Cocos Island">Cocos Island</option> <option value="Colombia">Colombia</option> <option value="Cook Islands">Cook Islands</option> <option value="Costa Rica">Costa Rica</option> <option value="Croatia">Croatia</option> <option value="Cuba">Cuba</option> <option value="Cyprus">Cyprus</option> <option value="Czech Republic">Czech Republic</option> <option value="Denmark">Denmark</option> <option value="Dominica">Dominica</option> <option value="Dominican Republic">Dominican Republic</option> <option value="Ecuador">Ecuador</option> <option value="Egypt">Egypt</option> <option value="El Salvador">El Salvador</option> <option value="Estonia">Estonia</option> <option value="Falkland Islands">Falkland Islands</option> <option value="Faroe Islands">Faroe Islands</option> <option value="Fiji">Fiji</option> <option value="Finland">Finland</option> <option value="France">France</option> <option value="French Guyana">French Guyana</option> <option value="French Polynesia">French Polynesia</option> <option value="Gabon">Gabon</option> <option value="Germany">Germany</option> <option value="Gibraltar">Gibraltar</option> <option value="Georgia">Georgia</option> <option value="Greece">Greece</option> <option value="Greenland">Greenland</option> <option value="Grenada">Grenada</option> <option value="Guadeloupe">Guadeloupe</option> <option value="Guatemala">Guatemala</option> <option value="Guinea-Bissau">Guinea-Bissau</option> <option value="Guinea">Guinea</option> <option value="Haiti">Haiti</option> <option value="Honduras">Honduras</option> <option value="Hong Kong">Hong Kong</option> <option value="Hungary">Hungary</option> <option value="Iceland">Iceland</option> <option value="India">India</option> <option value="Indonesia">Indonesia</option> <option value="Ireland">Ireland</option> <option value="Israel">Israel</option> <option value="Italy">Italy</option> <option value="Jamaica">Jamaica</option> <option value="Japan">Japan</option> <option value="Jordan">Jordan</option> <option value="Kazakhstan">Kazakhstan</option> <option value="Kenya">Kenya</option> <option value="Kiribati ">Kiribati </option> <option value="Kuwait">Kuwait</option> <option value="Kyrgyzstan">Kyrgyzstan</option> <option value="Lao People's Democratic Republic">Lao People's Democratic Republic</option> <option value="Latvia">Latvia</option> <option value="Lebanon">Lebanon</option> <option value="Liechtenstein">Liechtenstein</option> <option value="Lithuania">Lithuania</option> <option value="Luxembourg">Luxembourg</option> <option value="Macedonia">Macedonia</option> <option value="Madagascar">Madagascar</option> <option value="Malawi">Malawi</option> <option value="Malaysia ">Malaysia </option> <option value="Maldives">Maldives</option> <option value="Mali">Mali</option> <option value="Malta">Malta</option> <option value="Marocco">Marocco</option> <option value="Marshall Islands">Marshall Islands</option> <option value="Mauritania">Mauritania</option> <option value="Mauritius">Mauritius</option> <option value="Mexico">Mexico</option> <option value="Micronesia">Micronesia</option> <option value="Moldavia">Moldavia</option> <option value="Monaco">Monaco</option> <option value="Mongolia">Mongolia</option> <option value="Myanmar">Myanmar</option> <option value="Nauru">Nauru</option> <option value="Nepal">Nepal</option> <option value="Netherlands Antilles">Netherlands Antilles</option> <option value="Netherlands">Netherlands</option> <option value="New Zealand">New Zealand</option> <option value="Niue">Niue</option> <option value="North Korea">North Korea</option> <option value="Norway">Norway</option> <option value="Oman">Oman</option> <option value="Pakistan">Pakistan</option> <option value="Palau">Palau</option> <option value="Panama">Panama</option> <option value="Papua New Guinea">Papua New Guinea</option> <option value="Paraguay">Paraguay</option> <option value="Peru ">Peru </option> <option value="Philippines">Philippines</option> <option value="Poland">Poland</option> <option value="Portugal ">Portugal </option> <option value="Puerto Rico">Puerto Rico</option> <option value="Qatar">Qatar</option> <option value="Republic of Korea Reunion">Republic of Korea Reunion</option> <option value="Romania">Romania</option> <option value="Russia">Russia</option> <option value="Saint Helena">Saint Helena</option> <option value="Saint kitts and nevis">Saint kitts and nevis</option> <option value="Saint Lucia">Saint Lucia</option> <option value="Samoa">Samoa</option> <option value="San Marino">San Marino</option> <option value="Saudi Arabia">Saudi Arabia</option> <option value="Seychelles">Seychelles</option> <option value="Singapore">Singapore</option> <option value="Slovakia">Slovakia</option> <option value="Slovenia">Slovenia</option> <option value="Solomon Islands">Solomon Islands</option> <option value="South Africa">South Africa</option> <option value="Spain">Spain</option> <option value="Sri Lanka">Sri Lanka</option> <option value="St.Pierre and Miquelon">St.Pierre and Miquelon</option> <option value="St.Vincent and the Grenadines">St.Vincent and the Grenadines</option> <option value="Sweden">Sweden</option> <option value="Switzerland">Switzerland</option> <option value="Syria">Syria</option> <option value="Taiwan ">Taiwan </option> <option value="Tajikistan">Tajikistan</option> <option value="Thailand">Thailand</option> <option value="Trinidad and Tobago">Trinidad and Tobago</option> <option value="Turkey">Turkey</option> <option value="Turkmenistan">Turkmenistan</option> <option value="Turks and Caicos Islands">Turks and Caicos Islands</option> <option value="Ukraine">Ukraine</option> <option value="UAE">UAE</option> <option value="UK" selected>UK</option> <option value="USA">USA</option> <option value="Uruguay">Uruguay</option> <option value="Uzbekistan">Uzbekistan</option> <option value="Vanuatu">Vanuatu</option> <option value="Vatican City">Vatican City</option> <option value="Vietnam">Vietnam</option> <option value="Virgin Islands (GB)">Virgin Islands (GB)</option> <option value="Virgin Islands (U.S.) ">Virgin Islands (U.S.) </option> <option value="Wallis and Futuna Islands">Wallis and Futuna Islands</option> <option value="Yemen">Yemen</option> <option value="Yugoslavia">Yugoslavia</option> </select> </p> <p> <input name="user_code" type="text" size="10"> <img src="pngimg.php" align="middle"> </p> <p align="center"> <input type="submit" name="Submit" value="Register"> </p> </form> </div> </div> You can see what happens here http://www.myvee.co.uk/register.php You type in your details, and it all just goes blank, it just seems to refresh the page. The errors dont display either. Any help? thanks Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 one thing I notice is that you do all of your error checking, but then it seems that you try to insert into the database regardless of the result of your error checking. additionally, after inserting to the database you never redirect them to another page with the confirmation message, so all it will do is output the form again Quote Link to comment Share on other sites More sharing options...
JeanieTallis Posted March 30, 2009 Author Share Posted March 30, 2009 one thing I notice is that you do all of your error checking, but then it seems that you try to insert into the database regardless of the result of your error checking. additionally, after inserting to the database you never redirect them to another page with the confirmation message, so all it will do is output the form again I see what you mean by the first bit, though, its suppose to check for errors, and if theres no errors it's suppose to submit the form to the database, and then send a confirmation email. I don't recieve a confirmation email when registering, when I should do. Also, it is suppose to remove the form, and put a echo saying that an email is being sent to them. As quoted on line 80. echo("Registration Successful! An activation code has been sent to your email address with an activation link..."); Quote Link to comment Share on other sites More sharing options...
JeanieTallis Posted March 30, 2009 Author Share Posted March 30, 2009 Anybody got any suggestions Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 i dont see anywhere in the code where you echo $error also, make sure error reporting is turned on try something like this at the top, initialize $ifError = false; then for each time you check an error condition, if there is a problem then $ifError = true; then, if there are no errors, THEN you can process and mail the form if(!$ifError) { $_POST['username'] = strip_tags($_POST['username']); $_POST['password'] = strip_tags($_POST['password']); $_POST['country'] = strip_tags($_POST['country']); if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); $_POST['password'] = addslashes($_POST['password']); $_POST['email'] = addslashes($_POST['email']); $_POST['country'] = addslashes($_POST['country']); } $date_registered = date('m d, Y'); $md5pass = md5($_POST['passwrd_again']); $activ_code = rand(1000,9999); mysql_query("INSERT INTO users (`username`,`email`,`password`,`country`,`date_registered`,`activation_code`,`full_name`) VALUES ('$_POST[username]','$_POST[email]','$md5pass','$_POST[country]','$date_registered','$activ_code','$_POST[full_name]')") or die(mysql_error()); $message = "Dear $_POST[full_name] \n Thank you for registering an account with MyVee. Here are the login details...\n\n Username: $_POST[username] \n User Email: $_POST[email] \n Password: $_POST[password_confirmation] \n Activation Code: $activ_code \n ____________________________________________ *** ACTIVATION LINK ***** \n Activation Link: http://jeanies-poetry.com/activate.php?usr=$_POST[email]&code=$activ_code \n\n _____________________________________________ Thank you. This is an automated response. PLEASE DO NOT REPLY. "; mail($_POST['email'] , "Account Activation", $message, "From: \"Auto-Response\" <notifications@myvee.co.uk>\r\n" . "X-Mailer: PHP/" . phpversion()); unset($_SESSION['ckey']); echo("Registration Successful! An activation code has been sent to your email address with an activation link..."); exit; } } else { echo $error; } Quote Link to comment Share on other sites More sharing options...
JeanieTallis Posted March 30, 2009 Author Share Posted March 30, 2009 That does not work either, I don't know how to check for errors. I tried both $ifError = false; and $ifError = true; at the top of the page, and no errors come up Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 post the PHP section of the page again (the html form part is not necessary to post again) with your latest changes also, put this at the top of your page inside of <?php error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
JeanieTallis Posted March 30, 2009 Author Share Posted March 30, 2009 <?php error_reporting(E_ALL); $ifError = true; session_start(); include('db.php'); if (isset($_POST['submit'])) { if ( !$_POST['full_name'] || !$_POST['email'] || !$_POST['username'] || !$_POST['password'] || !$_POST['password'] == !$_POST['password_confirmed'] || !$_POST['country'] || !$_POST['user_code']) { $error = 'You did not fill in a required field!'; } if (strcmp(md5($_POST['user_code']),$_SESSION['ckey'])) { $error = 'Invalid code entered. Please enter the correct code as shown in the Image!'; } if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $qry = "SELECT username FROM users WHERE username = '".$_POST['username']."'"; $sqlmembers = mysql_query($qry) or die(mysql_error()); $name_check = mysql_fetch_array ($sqlmembers); $name_checkk = mysql_num_rows ($sqlmembers); if ($name_checkk != 0) { $error ='Sorry, the username: <strong>'.$_POST['username'].'</strong>' . ' is already taken, please pick another one. Click back.'; } if (!preg_match("/.*@.*..*/", $_POST['email']) || preg_match("/(<|>)/", $_POST['email'])) { $error = 'Invalid e-mail address.'; } if ($_POST['password'] != $_POST['password_confirmation']) { $error = 'Passwords did not match.'; } if(!$ifError) { $_POST['username'] = strip_tags($_POST['username']); $_POST['password'] = strip_tags($_POST['password']); $_POST['country'] = strip_tags($_POST['country']); if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); $_POST['password'] = addslashes($_POST['password']); $_POST['email'] = addslashes($_POST['email']); $_POST['country'] = addslashes($_POST['country']); } $date_registered = date('m d, Y'); $md5pass = md5($_POST['password_confirmation']); $activ_code = rand(1000,9999); mysql_query("INSERT INTO users (`username`,`email`,`password`,`country`,`date_registered`,`activation_code`,`full_name`) VALUES ('$_POST[username]','$_POST[email]','$md5pass','$_POST[country]','$date_registered','$activ_code','$_POST[full_name]')") or die(mysql_error()); $message = "Dear $_POST[full_name] \n Thank you for registering an account with MyVee. Here are the login details...\n\n Username: $_POST[username] \n User Email: $_POST[email] \n Password: $_POST[password_confirmation] \n Activation Code: $activ_code \n ____________________________________________ *** ACTIVATION LINK ***** \n Activation Link: http://jeanies-poetry.com/activate.php?usr=$_POST[email]&code=$activ_code \n\n _____________________________________________ Thank you. This is an automated response. PLEASE DO NOT REPLY. "; mail($_POST['email'] , "Account Activation", $message, "From: \"Auto-Response\" <notifications@myvee.co.uk>\r\n" . "X-Mailer: PHP/" . phpversion()); unset($_SESSION['ckey']); echo("Registration Successful! An activation code has been sent to your email address with an activation link..."); exit; } } else { echo $error; } ?> I put the php snippet you said, and I came up with this error "Notice: Undefined variable: error in /home/myveeco/public_html/register.php on line 85" which line 85 is else { echo $error; } Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 1) i said to initialize it as false $isError = false; this way, when the page is submitted it always assumes there are no errors at first, which is correct 2) if there IS an error, then set it to true (you didn't do this either) if (strcmp(md5($_POST['user_code']),$_SESSION['ckey'])) { $error = 'Invalid code entered. Please enter the correct code as shown in the Image!'; $ifError = true; } add the same condition into all of your error checking statements 3) use the [code ] tags properly when posting code please, it makes it so much easier to read Quote Link to comment Share on other sites More sharing options...
JeanieTallis Posted March 30, 2009 Author Share Posted March 30, 2009 error_reporting(E_ALL); $ifError = false; session_start(); include('db.php'); if (isset($_POST['submit'])) { if ( !$_POST['full_name'] || !$_POST['email'] || !$_POST['username'] || !$_POST['password'] || !$_POST['password'] == !$_POST['password_confirmed'] || !$_POST['country'] || !$_POST['user_code']) { $error = 'You did not fill in a required field!'; $ifError = true; } if (strcmp(md5($_POST['user_code']),$_SESSION['ckey'])) { $error = 'Invalid code entered. Please enter the correct code as shown in the Image!'; $ifError = true; } if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $qry = "SELECT username FROM users WHERE username = '".$_POST['username']."'"; $sqlmembers = mysql_query($qry) or die(mysql_error()); $name_check = mysql_fetch_array ($sqlmembers); $name_checkk = mysql_num_rows ($sqlmembers); if ($name_checkk != 0) { $error ='Sorry, the username: <strong>'.$_POST['username'].'</strong>' . ' is already taken, please pick another one. Click back.'; } if (!preg_match("/.*@.*..*/", $_POST['email']) || preg_match("/(<|>)/", $_POST['email'])) { $error = 'Invalid e-mail address.'; $ifError = true; } if ($_POST['password'] != $_POST['password_confirmation']) { $error = 'Passwords did not match.'; $ifError = true; } if(!$ifError) { $_POST['username'] = strip_tags($_POST['username']); $_POST['password'] = strip_tags($_POST['password']); $_POST['country'] = strip_tags($_POST['country']); if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); $_POST['password'] = addslashes($_POST['password']); $_POST['email'] = addslashes($_POST['email']); $_POST['country'] = addslashes($_POST['country']); } $date_registered = date('m d, Y'); $md5pass = md5($_POST['password_confirmation']); $activ_code = rand(1000,9999); mysql_query("INSERT INTO users (`username`,`email`,`password`,`country`,`date_registered`,`activation_code`,`full_name`) VALUES ('$_POST[username]','$_POST[email]','$md5pass','$_POST[country]','$date_registered','$activ_code','$_POST[full_name]')") or die(mysql_error()); $message = "Dear $_POST[full_name] \n Thank you for registering an account with MyVee. Here are the login details...\n\n Username: $_POST[username] \n User Email: $_POST[email] \n Password: $_POST[password_confirmation] \n Activation Code: $activ_code \n ____________________________________________ *** ACTIVATION LINK ***** \n Activation Link: http://jeanies-poetry.com/activate.php?usr=$_POST[email]&code=$activ_code \n\n _____________________________________________ Thank you. This is an automated response. PLEASE DO NOT REPLY. "; mail($_POST['email'] , "Account Activation", $message, "From: \"Auto-Response\" <notifications@myvee.co.uk>\r\n" . "X-Mailer: PHP/" . phpversion()); unset($_SESSION['ckey']); echo("Registration Successful! An activation code has been sent to your email address with an activation link..."); exit; } } else { echo $error; } Have I missed anything out? The same error comes up on the page. "Notice: Undefined variable: error in /home/myveeco/public_html/register.php on line 85" also nothing happens still. Just refreshes the page. Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 else { echo $error; } this is after the wrong if statement. move it up one line before the last } you can also initialize $error = ""; at the beginning of the statement Quote Link to comment Share on other sites More sharing options...
JeanieTallis Posted March 30, 2009 Author Share Posted March 30, 2009 Okay, I moved it up. The error disappears, but yet again, the form only refreshes, does not go into the database or send a confirmation email. It's really confusing me. Quote Link to comment 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.