My ques: page refreshes to initial state

December 19, 2010 at 02:38:07
Specs: Windows 7, 3gb
M trying to make a signup form in php, n dis iz d code,

<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("user_info",$con);
if (isset($_POST['submit']))
{ //This makes sure they did not leave any fields blank
if (!$_POST['email'] || !$_POST['password'] || !$_POST['password2'] || !$_POST['date'] || !$_POST['month'] || !$_POST['year'] || !$_POST['address'] || !$_POST['city'] || !$_POST['state'] || !$_POST['country'] || !$_POST['sex'])
{
die('You did not complete all of the required fields');

}
// checks if the username is in use
if (!get_magic_quotes_gpc())
{
$_POST['email'] = addslashes($_POST['email']);
}
$usercheck = $_POST['email'];
$check = mysql_query("SELECT email FROM users WHERE email = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0)
{

die('Sorry, the username '.$_POST['email'].' is already in use.');
}
// this makes sure both passwords entered match
if ($_POST['password'] != $_POST['password2'])
{
die('Your passwords did not match. ');
}
// here we encrypt the password and add slashes if needed
$_POST['password'] = md5($_POST['password']);
if (!get_magic_quotes_gpc())
{
$_POST['password'] = addslashes($_POST['password']);
$_POST['email'] = addslashes($_POST['email']);
}
// now we insert it into the database
$insert = "INSERT INTO users(email, password,date,month,year,city,state,country,name,sex,address)
VALUES ('".$_POST['email']."', '".$_POST['password']."', '".$_POST['date']."',
'".$_POST['month']."', '".$_POST['year']."', '".$_POST['ciy']."',
'".$_POST['state']."', '".$_POST['country']."', '".$_POST['name']."',
'".$_POST['sex']."', '".$_POST['address']."')";
$add_member = mysql_query($insert,$con);

?>
<h1>Registered</h1>

Thank you, you have registered - you may now login.</p>;
<?php
}
else
{
?>


<head>
<style type="text/css">

div.frm
{
color:black;
font-variant:small-caps;
position:auto;
top:0%;
left:65%;
text-align:justify;
font-size:15px;
line-height:200%;

}

label
{
width: 2em;
float: left;
text-align: right;
font-weight:bold;
margin-right: 9em;

}
.submit input
{
margin-left: 4.5em;
}
input
{
color: #781351;
background: #fee3ad;
border: 2px solid #781351
}
.submit input
{
color: #000;
background: #ffa20f;
border: 2px outset #d7b9c9
}
fieldset
{
border: 1px solid #781351;
width: 30em
}
legend
{
color: #fff;
background: #ffa20c;
border: 1px solid #781351;
padding: 2px 6px
}

body
{
background-image:url('sign.jpg');
background-repeat:repeat-y;
overflow:auto;
width:100%;
height:100%;
}
</style>
</head>


<body>
<div class="frm">

<form name="signup" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<legend>Signup Form</legend>

<label for="name">Name:</label><input type="text" name="name"/>

<tr><label for="birthday">Birthday:</label></td><td><div class="input"> <select name="date" id="date" onchange="" autocomplete="off">
<option value="-1">Day:</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select class="" id="month" name="month" onchange="return run_with(this, ["editor"], function() {editor_date_month_change(this, "birthday_day", "birthday_year");});">
<option value="-1">Month:</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="year" id="year" onchange="return run_with(this, ["editor"], function() {editor_date_month_change("birthday_month","birthday_day",this);});" autocomplete="off">
<option value="-1">Year:</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option> </select></div></td></tr>

<label for="name">Address:</label><input type="text" name="address"/>

<label for="name">City:</label><input type="text" name="city"/>

<label for="state">State:</label><input type="text" name="state"/>

<label for="name">Country</label></label><input type="text" name="country"/>

<label for="e-mail">E-MAIL</label><input type="text" name="email"/>

<label for="password">Password</label><input type="password" name="password"/>

<label for="confirm">Confirm</label><input type="password" name="password2"/>

<label for="sex">Sex:</label>

<center><input type="radio" name="sex" value="male" /> Male<br />
<center><input type="radio" name="sex" value="female" /> Female

<center><input type="submit" value="Sign Up"></center>
</fieldset>
</form>

</div>


</body>
</html>

<?php
}
mysql_close($con);
?>

but aftre i enter d fields, it should go and print 'u ve been registered', but it comes back to signup form. M unable to find problem with the code. any help!

DK


See More: My ques: page refreshes to initial state

Report •


#1
December 20, 2010 at 16:55:48
if(isset($_POST["submit"])) { ... }

$_POST["submit"] isn't defined, so your program is taking the else path. Try giving your submit button a name.

if(isset($_POST["cmd"]) && $_POST["cmd"] === "Sign Up") { ... } else { ... }
<input name="cmd" value="Sign Up" type="submit">


Report •
Related Solutions


Ask Question