1,105,395 Community Members

my php form not posting to database

Member Avatar
stutego
Newbie Poster
4 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

SO this isn't register.php?

Member Avatar
ehpratah
Junior Poster
140 posts since May 2012
Reputation Points: 27 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 2 [?]
 
0
 

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

Member Avatar
TonyG_cyprus
Posting Whiz
329 posts since Dec 2009
Reputation Points: 36 [?]
Q&As Helped to Solve: 47 [?]
Skill Endorsements: 2 [?]
 
0
 

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.

Member Avatar
AARTI SHRIVAS
Posting Pro in Training
410 posts since Dec 2012
Reputation Points: 2 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 3 [?]
 
0
 

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

Member Avatar
AARTI SHRIVAS
Posting Pro in Training
410 posts since Dec 2012
Reputation Points: 2 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 3 [?]
 
0
 
<INPUT TYPE=SUBMIT VALUE="Register">
<INPUT TYPE="submit" VALUE="Register" name="submit">

check this

Member Avatar
stutego
Newbie Poster
4 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 85 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
0
 
<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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: