Jump to content

Recommended Posts

OK, I posted earlier about some code that I was having a problem with and you guys were extremely helpful so the problem was solved in just a few minutes.  Here's the same code, different problem:  When the page is visited the code checks to see if the form on the page has been submitted, if not it shows the form.  When the form is submitted the information is inserted into the database and the page should redirect to the login page.  The problem is, the page isn't redirecting, it just reloads the same page and, because the form has been submitted, the page is now blank.  Can anyone help out and let me know why the page isn't redirecting to the login page?  Thanks in advance for your help.  Here is the code:

<?php
include("conf.inc.php"); // Includes the db and form info.
if (!isset($_POST['submit'])) { // If the form has not been submitted.
echo "<form action=\"signup.php\" method=\"POST\">";
echo "<div align=\"center\">";
echo "<table width=\"645\" border=\"2\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#FFFFFF\">";
echo "<tr>";
echo "<td width=\"640\" height=\"321\" align=\"center\" valign=\"top\">";
echo "<p align=\"left\"><strong><font color=\"#FFFFFF\" size=\"5\"> Customer Sign-Up...<br>";
echo "</font></strong><font color=\"#FF0000\"> The following information will be used only to contact you regarding your service.</font></p>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">First Name:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<input name=\"fname\" type=\"text\" id=\"fname\" size=\"37\" maxlength=\"25\">";
echo "</td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">Last Name:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<input name=\"lname\" type=\"text\" id=\"lname\" size=\"37\" maxlength=\"25\">";
echo "</td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">Home Address:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<input name=\"haddress\" type=\"text\" id=\"haddress\" size=\"37\" maxlength=\"35\">";
echo "</td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">City, State & Zip:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<input name=\"hcity\" type=\"text\" id=\"hcity\" size=\"18\" maxlength=\"20\">";
echo ",";
echo "<select name=\"hstate\" id=\"hstate\">";
echo "<option value=\"AL\">AL</option>";
echo "<option value=\"AK\">AK</option>";
echo "<option value=\"AZ\">AZ</option>";
echo "<option value=\"AR\">AR</option>";
echo "<option value=\"CA\">CA</option>";
echo "<option value=\"CO\">CO</option>";
echo "<option value=\"CT\">CT</option>";
echo "<option value=\"DE\">DE</option>";
echo "<option value=\"DC\">DC</option>";
echo "<option value=\"FL\">FL</option>";
echo "<option value=\"GA\">GA</option>";
echo "<option value=\"HI\">HI</option>";
echo "<option value=\"ID\">ID</option>";
echo "<option value=\"IL\">IL</option>";
echo "<option value=\"IN\">IN</option>";
echo "<option value=\"IA\">IA</option>";
echo "<option value=\"KS\">KS</option>";
echo "<option value=\"KY\">KY</option>";
echo "<option value=\"LA\">LA</option>";
echo "<option value=\"ME\">ME</option>";
echo "<option value=\"MD\">MD</option>";
echo "<option value=\"MA\">MA</option>";
echo "<option value=\"MI\">MI</option>";
echo "<option value=\"MN\">MN</option>";
echo "<option value=\"MS\">MS</option>";
echo "<option value=\"MO\">MO</option>";
echo "<option value=\"MT\">MT</option>";
echo "<option value=\"NE\">NE</option>";
echo "<option value=\"NV\">NV</option>";
echo "<option value=\"NH\">NH</option>";
echo "<option value=\"NJ\">NJ</option>";
echo "<option value=\"NM\">NM</option>";
echo "<option value=\"NY\">NY</option>";
echo "<option value=\"NC\">NC</option>";
echo "<option value=\"ND\">ND</option>";
echo "<option value=\"OH\">OH</option>";
echo "<option value=\"OK\">OK</option>";
echo "<option value=\"OR\">OR</option>";
echo "<option value=\"PA\">PA</option>";
echo "<option value=\"RI\">RI</option>";
echo "<option value=\"SC\">SC</option>";
echo "<option value=\"SD\">SD</option>";
echo "<option value=\"TN\">TN</option>";
echo "<option value=\"TX\" selected>TX</option>";
echo "<option value=\"UT\">UT</option>";
echo "<option value=\"VT\">VT</option>";
echo "<option value=\"VA\">VA</option>";
echo "<option value=\"WA\">WA</option>";
echo "<option value=\"WV\">WV</option>";
echo "<option value=\"WI\">WI</option>";
echo "<option value=\"WY\">WY</option>";
echo "</select>";
echo "  <input name=\"hzip\" type=\"text\" id=\"hzip\" size=\"3\" maxlength=\"5\">";
echo "</td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">Home Phone:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<input name=\"hphone\" type=\"text\" id=\"hphone\" size=\"37\" maxlength=\"14\">";
echo "<font size=\"2\"><br>";
echo "<font color=\"#999999\">Include area code (i.e. 940-555-1234)</font></font></td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">Email Address:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<input name=\"email\" type=\"text\" id=\"email\" size=\"37\" maxlength=\"40\">";
echo "<br>";
echo "<font color=\"#999999\" size=\"2\">(Your email will also be your user ID.)</font></td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">Choose a Password:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<input name=\"pword\" type=\"password\" id=\"pword\" size=\"37\" maxlength=\"20\">";
echo "<br>";
echo "<font color=\"#999999\"size=\"2\">(Minimum of 6 characters in length.)</font></td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">Re-enter Password:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<input name=\"pword2\" type=\"password\" id=\"pword2\" size=\"37\" maxlength=\"20\">";
echo "</td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" height=\"24\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">Security Question:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<select name=\"question\" id=\"question\">";
echo "<option value=\"0\" selected>--Choose a security question--</option>";
echo "<option value=\"What was your high school mascot?\">What was your high school mascot?</option>";
echo "<option value=\"What is your mother's maiden name?\">What is your mother's maiden name?</option>";
echo "<option value=\"What was your first car?\">What was your first car?</option>";
echo "<option value=\"Who was your favorite teacher?\">Who was your favorite teacher?</option>";
echo "<option value=\"What is your library card number?\">What is your library card number?</option>";
echo "</select>";
echo "</td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"187\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">Answer:</font></strong></td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<input name=\"answer\" type=\"text\" id=\"answer\" size=\"37\" maxlength=\"35\">";
echo "</td>";
echo "</tr>";
echo "</table><br>";
echo "<table width=\"625\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
echo "<tr>";
echo "<td width=\"187\" height=\"102\" align=\"left\" valign=\"top\"><strong><font color=\"#FFFFFF\">Terms of Service:</font></strong></td>";
echo "<td width=\"438\" align=\"right\" valign=\"top\">";
echo "<textarea cols=\"40\" rows=\"5\" readonly=\"readonly\" wrap=\"VIRTUAL\" style=\"width:100%;text-align:\" onfocus=\"this.rows=10\">";
echo "Terms of Service text goes here.";
echo "</textarea>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td> </td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\"><font color=\"#FFFFFF\">";
echo "By clicking 'I accept' below, you are agreeing to the Terms of Service and the Alleyway Oil & Lube Service Agreement.</font></td>";
echo "</tr>";
echo "</table>";
echo "<table width=\"625\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td> </td>";
echo "<td width=\"438\" align=\"left\" valign=\"top\">";
echo "<div align=\"left\">";
echo "<input name=\"submit\" type=\"submit\" value=\"I accept, continue to my account.\" onClick=\"return validate(form)\">";
echo "</div></td>";
echo "</tr>";
echo "</table>";
echo "<br>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
echo "</form>";

} else { // The form has been submitted.

$fname = form($_POST['fname']);
    $lname = form($_POST['lname']);
    $haddress = form($_POST['haddress']);
    $hcity = form($_POST['hcity']);
    $hstate = form($_POST['hstate']);
    $hzip = form($_POST['hzip']);
    $hphone = form($_POST['hphone']);
    $email = form($_POST['email']);
    $pword = md5($_POST['pword']);  // Encrypts the password.
    $question = form($_POST['question']);
    $answer = form($_POST['answer']);


$q = mysql_query("SELECT * FROM `users` WHERE email = '$email'") or die (mysql_error()); // mySQL Query
$r = mysql_num_rows($q); // Checks to see if anything is in the db.

if ($r > 0) { // If there are users with the same email.
	exit("That email is already registered!");
} else {
	mysql_query("INSERT INTO `users` (fname,lname,haddress,hcity,hstate,hzip,hphone,email,pword,question,answer) VALUES ('$fname','$lname','$haddress','$hcity','$hstate','$hzip','$hphone','$email','$pword','$question','$answer')") or die (mysql_error()); // Inserts the user info.
	header("Location: login.php"); // Back to login.
}
}
mysql_close($db_connect); // Closes the connection.
?>

Link to comment
https://forums.phpfreaks.com/topic/120779-solved-page-redirect/
Share on other sites

OK, I've tried both of your suggestions but neither worked... I basically made it to where if the form has been submitted it would insert the information into the data base and if not the form is displayed.  The code worked fine except it didn't redirect to the login page... same problem as before.  Any other ideas?

Link to comment
https://forums.phpfreaks.com/topic/120779-solved-page-redirect/#findComment-622556
Share on other sites

OK everyone, thanks for the help but what I was doing was working all along.  I'm using a free web hosting service to test my site until I get it finished and I guess there was some function that was disabled or something because when I tried it using a different hosting company it worked fine.  Sorry to waste everyone's time.

Link to comment
https://forums.phpfreaks.com/topic/120779-solved-page-redirect/#findComment-622603
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.