Jump to content

Recommended Posts

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>






Link to comment
https://forums.phpfreaks.com/topic/273397-form-not-posting-to-database/
Share on other sites

  • 2 weeks later...
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.