Jump to content


Photo

form not posting to database

form database help with form

  • Please log in to reply
2 replies to this topic

#1 stutego

stutego

    Member

  • Members
  • PipPip
  • 23 posts
  • Age:22

Posted 20 January 2013 - 01:24 PM

form not posting to database
instead its redirecting me to another page with heading "object not found!"


<?php
   $connect= mysql_connect("localhost", "username", "password");
   if (!$connect)
   {
   die("could'nt connect to db:".mysql_error());
   }
   mysql_select_db("myapp", $connect);
   $sql="INSERT INTO form(fname,lname,email,password,telephone,sex,dob)
   VALUES
   ('','$_POST[fname]', '$_POST[lname]', '$_POST[email]' '$_POST[password]', '$_POST[telephone]', '$_POST[sex]', '$_POST[dob]')";
   if (!mysql_query($sql, $connect))
    {
die("Error:" .mysql_error());
    }
mysql_close($connect);



function spamcheck($field)
{
$field = filter_var($field, FILTER_SANITIZE_EMAIL);
if(filter_var ($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_POST['email']))
{
$mailcheck = spamcheck($_POST['email']);
}
if($mailcheck == FALSE)
{
//echo "invalid input";
}
else
{
$email=$_POST['email'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$password=$_POST['password'];
$retype_password=$password;
$telephone=$_POST['telephone'];
$sex=$_POST['sex'];
$DOB=$_POST['dob'];
}



 function yearOptions()
    {
	    for ($i = 1910; $i <= date('Y'); $i++)
        {
    $s = date('Y') == $i ? ' selected="selected"' : '';
    echo '<option '.$s.' value="'.$i.'">'.$i.'</option>'."\n";
    }
    }
   
    function monthOptions()
    {
	    $months = array( 1 => "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
	   
	    foreach ( $months as $monthNo => $month )
	    {
		    ( $monthNo == date('n') ) ? $selected = ' selected="selected"' : $selected = '';
		    echo '<option value="'.$monthNo.'"'.$selected.'>'.$month.'</option>'."\n";
	    }
    }
   
    function dayOptions()
    {
	    for ( $i = 1; $i <= 31; $i++ )
	    {
		    ( $i == date('j') ) ? $selected = ' selected="selected"' : $selected = '';
		    echo '<option value="'.$i.'"'.$selected.'>'.$i.'</option>'."\n";
	    }
    }
   
    $password=$_POST["password"];
    $salt=rand(100000,999999);
        $encrypted= (MD5(MD5($salt.$password)));
    if($retype_password!=$password)
    {
    echo "password mismatch";
    }


       


?>
<form action = "register.php" method=post>
<fieldset>
Firstname:
<input type="text" size=30 name="fname"><br>

Lastname:
<input type="text" size=30 name="lname"><br>

Email address:
<input type=text size=30 name="email"><br>

Password:
<input type=password size=30 name="password"><br>

Retype Password:
<input type=password size=30 name="retype_password"><br>

Telephone:
<input type=tel size=30 name="telephone"><br>

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

Date of birth:
<select name="dob">
<?php dayOptions();?>
</select>
<select name="dob">
<?php monthOptions();?>
</select>
<select name="dob">
<?php yearOptions();?>
</select><br>

<INPUT TYPE=SUBMIT VALUE="Register">
</fieldset>
</form>





 


#2 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 21 January 2013 - 08:42 AM

Error: Not enough information, please read this.
Keeping it simple.

#3 albertdiones

albertdiones

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 03 February 2013 - 10:28 PM

Make sure that

<form action = "register.php" method=post>


register.php actually exists. better yet, just remove it


<form method=post>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com