cfgcjm Posted September 30, 2007 Share Posted September 30, 2007 This is a registration script and on success it is supposed to send you to a page "regsuccess.php" but instead it is going to a white screen with the text "thank you for registering!" <?php /* Registration Script*/ require ('mysql.php'); if (isset ($_POST['submit'])) { // Check to see if the form has been submitted $username = $_POST['username']; $password = md5 ($_POST['password']); // MD5 encrypt the password so it is more secure $regkey = $_POST['regkey']; // See if the key is valid $sql = "SELECT * FROM reg_keys WHERE regkey='$regkey' LIMIT 1"; if ($r = mysql_query ($sql)) { $num = mysql_num_rows ($r); if ($num > 0) { // if there is a row with that key, the key is valid // The key is valid, add user to the database $add_sql = "INSERT INTO users (users_id, username, password, regkey) VALUES (0, '$username', '$password', '$regkey')"; // We make the first value (for users_id) 0 because it is set to auto increment, // so the users_id will be assigned to the next available number if ($add_r = mysql_query ($add_sql)) { // The user successfully registered header("location:regsuccess.php"); exit; // Delete the key from the key database, so it cannot be used again mysql_query ("DELETE FROM reg_keys WHERE regkey='$regkey'"); } else { // The user did not successfully register print 'Error:' . mysql_error(); // print the MySQL error } } else { // The key is not valid print 'The registration key you entered was not valid!'; } } else { // The regkey check query failed print 'Error:' . mysql_error(); // print the MySQL error } } else { // The form was not submitted // Display the form print '<table height="100%" align="center" valign="center"> <td> <form action="register.php" method="post"> <table border="0"> <tr> <td align="right" style="color: #fff;">Username:</td> <td align="center"><input type="text" name="username" /></td> </tr> <tr> <td align="right" style="color: #fff;">Password:</td> <td align="center"><input type="password" name="password" /></td> </tr> <tr> <td align="right" style="color: #fff;">Registration Key:</td> <td align="center"><input type="text" name="regkey" /></td> </tr> <tr> <td></td> <td align="center"><input type="submit" name="submit" value="Register" /></td> </tr> </table> </form>'; } ?> <style type="text/css"> <!-- body { background-image: url(images/flash%20back2.jpg); } --> </style> Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/ Share on other sites More sharing options...
Ninjakreborn Posted September 30, 2007 Share Posted September 30, 2007 header("Location: url"); if that doesn't work then paste the error. Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358406 Share on other sites More sharing options...
sKunKbad Posted September 30, 2007 Share Posted September 30, 2007 It's for sure not going to work because you can't have a header redirect that far down in the script. You need to look at your register.php. That is what is giving the message. Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358409 Share on other sites More sharing options...
Ninjakreborn Posted September 30, 2007 Share Posted September 30, 2007 Technically you can have one as far down as you want as long as there is nothing outputted to the browser before it shows. I see nothing there that outputs before the header, but yeah he's right, check the included file. That's why i stated, try that. If it doesn't work post the exact error message. Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358411 Share on other sites More sharing options...
cfgcjm Posted September 30, 2007 Author Share Posted September 30, 2007 Did the same thing...there isn't really an error it just prints "Thank you for registering!" on a white screen If you'd like to take a look http://www.stjohnsuccjonestown.org/portal/registration.php use one of these registration keys: 091273812469 091273812468 091273812467 Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358413 Share on other sites More sharing options...
sKunKbad Posted September 30, 2007 Share Posted September 30, 2007 it doesn't just magically print "thankyou for registering". You will have to search through your scripts and find the one that is outputing that. Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358414 Share on other sites More sharing options...
Ninjakreborn Posted September 30, 2007 Share Posted September 30, 2007 Post ALL of your code. The include, the registration page, and the other page. Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358418 Share on other sites More sharing options...
cfgcjm Posted September 30, 2007 Author Share Posted September 30, 2007 mysql.php <?php /* Connect To MySQL */ $host = 'db1150.perfora.net'; // your host name $dbuser = 'yyyyy'; // your database username $dbpass = 'xxxxx'; // your database user password $dbname = 'db219054840'; // your database name $connect = @mysql_connect ($host, $dbuser, $dbpass) or die ('Could not connect to MySQL!'); // attempt to connect $select_db = @mysql_select_db ($dbname) or die ('Could not select database!'); // attempt to select database ?> Registration Page <?php /* Registration Script*/ require ('mysql.php'); if (isset ($_POST['submit'])) { // Check to see if the form has been submitted $username = $_POST['username']; $password = md5 ($_POST['password']); // MD5 encrypt the password so it is more secure $regkey = $_POST['regkey']; // See if the key is valid $sql = "SELECT * FROM reg_keys WHERE regkey='$regkey' LIMIT 1"; if ($r = mysql_query ($sql)) { $num = mysql_num_rows ($r); if ($num > 0) { // if there is a row with that key, the key is valid // The key is valid, add user to the database $add_sql = "INSERT INTO users (users_id, username, password, regkey) VALUES (0, '$username', '$password', '$regkey')"; // We make the first value (for users_id) 0 because it is set to auto increment, // so the users_id will be assigned to the next available number if ($add_r = mysql_query ($add_sql)) { // The user successfully registered header("Location: http://www.stjohnsuccjonestown.org/portal/regsuccess.php"); exit; // Delete the key from the key database, so it cannot be used again mysql_query ("DELETE FROM reg_keys WHERE regkey='$regkey'"); } else { // The user did not successfully register print 'Error:' . mysql_error(); // print the MySQL error } } else { // The key is not valid print 'The registration key you entered was not valid!'; } } else { // The regkey check query failed print 'Error:' . mysql_error(); // print the MySQL error } } else { // The form was not submitted // Display the form print '<table height="100%" align="center" valign="center"> <td> <form action="register.php" method="post"> <table border="0"> <tr> <td align="right" style="color: #fff;">Username:</td> <td align="center"><input type="text" name="username" /></td> </tr> <tr> <td align="right" style="color: #fff;">Password:</td> <td align="center"><input type="password" name="password" /></td> </tr> <tr> <td align="right" style="color: #fff;">Registration Key:</td> <td align="center"><input type="text" name="regkey" /></td> </tr> <tr> <td></td> <td align="center"><input type="submit" name="submit" value="Register" /></td> </tr> </table> </form>'; } ?> <style type="text/css"> <!-- body { background-image: url(images/flash%20back2.jpg); } --> </style> Success Page <?php /* Login Script */ require ('mysql.php'); session_start(); if (isset ($_POST['submit'])) { // Check to see if the form has been submitted $username = $_POST['username']; $password = md5 ($_POST['password']); // we MD5 encrypted the password at registration, // so we must do this on the login as well // See if the user exists $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'"; if ($r = mysql_query ($sql)) { $row = mysql_fetch_array ($r); $num = mysql_num_rows ($r); if ($num > 0) { // if there is a row with that username/password, the user exists // Now we can assign some SESSIONS, so we can verify on later pages that the user is "logged in" $_SESSION['users_id'] = $row['users_id']; $_SESSION['username'] = $row['username']; $_SESSION['loggedin'] = TRUE; // This is where we will check to see if the user is logged in header("Location:portal.php"); exit; } else { // User does not exist header("location:login2.php"); exit; } } else { // The query failed print 'Error:' . mysql_error(); // print the MySQL error } } else { // The form was not submitted // Display the form print'<table height="100%" align="center" valign="center"> <td> <form action="login.php" method="post"> <table border="0" align="center" valign="center"> <tr> <td align="center" style="color: #fff;">Username:</td> <td align="center"><input type="text" name="username" /></td> </tr> <tr> <td align="center" style="color: #fff;">Password:</td> <td align="center"><input type="password" name="password" /></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Login" /></td> </tr> </table> </form>'; } ?> <style type="text/css"> <!-- body { background-image: url(images/flash%20back2.jpg); } .style1 { border-width: 0px; } .style2 { text-align: center; font-family: Verdana; font-size: 10pt; color: #FFFFFF; background-color: #009933; } --> </style> <div style="position: absolute; width: 321px; height: 19px; z-index: 1; left: 136px; top: 59px" id="layer2" class="style2"> <strong>Your Registration has suceeded!</strong></div> <div style="position: absolute; width: 72px; height: 25px; z-index: 1; left: 524px; top: 330px" id="layer1"> <a href="http://www.stjohnsuccjonestown.org/portal/registration.php"> <img src="images/register.gif" width="68" height="16" class="style1"></a></div> Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358419 Share on other sites More sharing options...
Ninjakreborn Posted September 30, 2007 Share Posted September 30, 2007 It looks like it's working. It takes you to the success page which is what you wanted? Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358422 Share on other sites More sharing options...
cfgcjm Posted September 30, 2007 Author Share Posted September 30, 2007 i just found the error and corrected it if you look in the registration page code at the bottom near the form it said <form action="register.php" method="post"> instead of <form action="registration.php" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358423 Share on other sites More sharing options...
cfgcjm Posted September 30, 2007 Author Share Posted September 30, 2007 is there a way to use header() twice? I need to direct to urls depending on an error. this is not working once the second header(Location:) is added <?php /* Registration Script*/ require ('mysql.php'); if (isset ($_POST['submit'])) { // Check to see if the form has been submitted $username = $_POST['username']; $password = md5 ($_POST['password']); // MD5 encrypt the password so it is more secure $regkey = $_POST['regkey']; // See if the key is valid $sql = "SELECT * FROM reg_keys WHERE regkey='$regkey' LIMIT 1"; if ($r = mysql_query ($sql)) { $num = mysql_num_rows ($r); if ($num > 0) { // if there is a row with that key, the key is valid // The key is valid, add user to the database $add_sql = "INSERT INTO users (users_id, username, password, regkey) VALUES (0, '$username', '$password', '$regkey')"; // We make the first value (for users_id) 0 because it is set to auto increment, // so the users_id will be assigned to the next available number if ($add_r = mysql_query ($add_sql)) { // The user successfully registered header("Location: http://www.stjohnsuccjonestown.org/portal/regsuccess.php"); exit; // Delete the key from the key database, so it cannot be used again mysql_query ("DELETE FROM reg_keys WHERE regkey='$regkey'"); } else { // The user did not successfully register print 'Error:' . mysql_error(); // print the MySQL error } } else { // The key is not valid header("Location: http://www.stjohnsuccjonestown.org/portal/registrationretry.php"); exit; } } else { // The regkey check query failed print 'Error:' . mysql_error(); // print the MySQL error } } else { // The form was not submitted // Display the form print '<table height="100%" align="center" valign="center"> <td> <form action="registration.php" method="post"> <table border="0"> <tr> <td align="right" style="color: #fff;">Username:</td> <td align="center"><input type="text" name="username" /></td> </tr> <tr> <td align="right" style="color: #fff;">Password:</td> <td align="center"><input type="password" name="password" /></td> </tr> <tr> <td align="right" style="color: #fff;">Registration Key:</td> <td align="center"><input type="text" name="regkey" /></td> </tr> <tr> <td></td> <td align="center"><input type="submit" name="submit" value="Register" /></td> </tr> </table> </form>'; } ?> <style type="text/css"> <!-- body { background-image: url(images/flash%20back2.jpg); } .style1 { text-align: center; border: 0px solid #000080; } .style4 { text-align: center; border: 1px solid #000080; background-color: #3333FF; } .style5 { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; color: #FFFFFF; } .style6 { line-height: 20px; font-family: verdana; font-size: 9px; font-weight: bold; color: #FFFFFF; } --> </style> <script type="text/javascript"> <!-- function FP_changeProp() {//v1.0 var args=arguments,d=document,i,j,id=args[0],o=FP_getObjectByID(id),s,ao,v,x; d.$cpe=new Array(); if(o) for(i=2; i<args.length; i+=2) { v=args[i+1]; s="o"; ao=args[i].split("."); for(j=0; j<ao.length; j++) { s+="."+ao[j]; if(null==eval(s)) { s=null; break; } } x=new Object; x.o=o; x.n=new Array(); x.v=new Array(); x.n[x.n.length]=s; eval("x.v[x.v.length]="+s); d.$cpe[d.$cpe.length]=x; if(s) eval(s+"=v"); } } function FP_getObjectByID(id,o) {//v1.0 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id); else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el; if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c) for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; } f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements; for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } } return null; } function FP_changePropRestore() {//v1.0 var d=document,x; if(d.$cpe) { for(i=0; i<d.$cpe.length; i++) { x=d.$cpe[i]; if(x.v=="") x.v=""; eval("x."+x.n+"=String(x.v)"); } d.$cpe=null; } } // --> </script> <div style="position: absolute; width: 23px; height: 22px; z-index: 1; left: 438px; top: 171px" id="layer1"> <img src="images/info.gif" width="19" height="19" onmouseover="FP_changeProp(/*id*/'layer2',0,'style.visibility','visible')" onmouseout="FP_changePropRestore()"></div> <div style="position: absolute; width: 405px; height: 56px; z-index: 2; left: 98px; top: 258px; visibility: hidden" id="layer2" class="style4"> <p class="style6"><strong> <span style="line-height: 115%; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA" class="style5"> The registration key is code that is used to validate that you are a member of St. John's UCC. If you do not have a registration key and would like one please see the pastor.</span></strong></p> </div> <div style="position: absolute; width: 72px; height: 25px; z-index: 1; left: 524px; top: 330px" id="layer3"> <a href="http://www.stjohnsuccjonestown.org/portal/login.php"> <img src="images/login.gif" width="68" height="16" class="style1"></a></div> Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358486 Share on other sites More sharing options...
BlueSkyIS Posted September 30, 2007 Share Posted September 30, 2007 if ($somecondition) { header("location: someplace.php"); exit; } else if ($someothercondition) { header("location: anotherplace.php"); exit; } else { header("location: yetanotherplace.php"); exit; } // Or you're still on the page Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358490 Share on other sites More sharing options...
cfgcjm Posted September 30, 2007 Author Share Posted September 30, 2007 i'm confused...isn't that what i have? Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358494 Share on other sites More sharing options...
desithugg Posted September 30, 2007 Share Posted September 30, 2007 woops sorry. Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358495 Share on other sites More sharing options...
BlueSkyIS Posted September 30, 2007 Share Posted September 30, 2007 Ay carumba, just yesterday some person was trying to tell me that the L has to be upper case. Today, it's lower case. IT DOESN'T MAKE A DIFFERENCE. This works exactly the same: header("LoCaTiOn: someurl.php"); exit; Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358497 Share on other sites More sharing options...
cfgcjm Posted September 30, 2007 Author Share Posted September 30, 2007 yes i know it doesn't matter...my code works fine with one occurance or the other simply not both Quote Link to comment https://forums.phpfreaks.com/topic/71259-solved-headerlocation-problem/#findComment-358500 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.