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>
Member Avatar for diafol

SO this isn't register.php?

you have an error in your insert statement try removing this part '', before this '$_POST[fname]',at the beginning of your statement

if this is register.php change this line

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

to this

<form action="" method="post">

also I noticed that you are double encrypting the password and salting with a
random number in the 100,000 range, I would think that gives a 100,000 to 1 chance of it being the same when a
user tries to log on.... think about it.
EDIT: I just scanned your code again, there are a few mistakes, extra spaces, missing comma's ect,
you should read carefully through it making corrections as you go. Use a reference manual.

in insert query give null instead of '' before fname and remove register.php from action in form tag.

<INPUT TYPE=SUBMIT VALUE="Register">
<INPUT TYPE="submit" VALUE="Register" name="submit">

check this

tanx all 4 helping out, but wat i didnt understand is the "register.php" part of it

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

action = the page/script to submit the data to on form submission
method = the way in which the data is sent to the script

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

method POST - will send the contents of "fname" and "lname" to the script defined in action - its sent in a hidden method along with the headers of the request - an empty action will send the data back to the same page(still across the internet to the server). It is recieved in the $_POST array so are accessible via $_POST['fname'] and $_POST['lname'];

method GET - will send the variables in the url(address bar) "page.php?fname=blah&lname=blah". Its generally not as secure as the vars get stored in the users history etc. They are stored in the $_GET array on the recieving page and are accessible via $_GET['fname'] and $_GET['lname'];

Diafol mentioned it cause of course the script defined in action is what writes to the database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.