data form to sql database using xampp
i am trying to insert record that user insert to register into database using this code but when i go to database I do not find any record insert it into my database so what's wrong ??? by the way i made my database using xampp program
<?php
if (isset($_POST['Postback']))
{
mysq开发者_如何学编程l_connect ("localhost") or die ('Error: ' .mysql_error());
mysql_select_db ("car_rental_db");
$Gender ='Female';
if ($_POST['RadioGender'] == 'Radio')
{
$Gender ='Male';
}
if($_POST['PasswordField']!= $_POST['ConfirmPassword'])
{
echo "This password doesn't match the confirmation password.<br>";
}
else if (strlen($_POST['PasswordField']) < 6 && strlen($_POST['PasswordField']) > 1)
{
echo "Your password must be longer than 6 characters.<br>";
}
else if ($_POST['PasswordField']== '')
{
echo "Please type a password, and then retype it to confirm.<br>";
}
else
{
}
$query = "INSERT INTO register_user (`FirstName`,`LastName`,`Email`,`Gender`,`Password`,`Birthday`,`Country`,`State`) VALUES('null'". $_POST['FirstName'] ."','". $_POST['LastName'] ."','" . $_POST['EmailField']."','".$Gender."','". $_POST['PasswordField'] ."','". $_POST['BirthdayTextFiled'] ."','". $_POST['SelectCountry'] ."','". $_POST['SelectState'] ."')";
echo $query;
//die ;
//header('Location: http://localhost/website/index.php');
}
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="RegistrationForm">
My dear your are doing echo
to your query not running it.
After your query add this line
mysql_query($query);
Edit And your code is also making no sense. Your query will run even if some of the condition above is false. Plase your in last else and it should look like
Gender ='Female';
if ($_POST['RadioGender'] == 'Radio')
{
$Gender ='Male';
}
if($_POST['PasswordField']!= $_POST['ConfirmPassword'])
{
echo "This password doesn't match the confirmation password.<br>";
}
else if (strlen($_POST['PasswordField']) < 6 && strlen($_POST['PasswordField']) > 1)
{
echo "Your password must be longer than 6 characters.<br>";
}
else if ($_POST['PasswordField']== '')
{
echo "Please type a password, and then retype it to confirm.<br>";
}
else
{
$query = "INSERT INTO register_user (`FirstName`,`LastName`,`Email`,`Gender`,`Password`,`Birthday`,`Country`,`State`) VALUES('null'". $_POST['FirstName'] ."','". $_POST['LastName'] ."','" . $_POST['EmailField']."','".$Gender."','". $_POST['PasswordField'] ."','". $_POST['BirthdayTextFiled'] ."','". $_POST['SelectCountry'] ."','". $_POST['SelectState'] ."')";
$rs=mysql_query($query);
}
// connect to server
mysql_connect ("localhost") or die ('Error: ' .mysql_error());
// select the correct database
mysql_select_db ("car_rental_db");
// execute query
mysql_query($query);
You should understand what you are trying to do before you try it. Go through some basic tutorial for PHP / MySQL to help you understand the basics.
精彩评论