我正在尝试插入用户插入的记录,使用此代码注册到数据库但是当我去数据库时,我没有找到任何记录将其插入我的数据库,所以出了什么问题? 顺便说一句,我使用xampp程序创建我的数据库
<?php
if (isset($_POST['Postback']))
{
mysql_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">
答案 0 :(得分:0)
亲爱的,您正在echo
对您的查询进行操作。
在您的查询后添加此行
mysql_query($query);
修改强> 你的代码也毫无意义。即使上面的某些条件为false,您的查询也会运行。放在最后的其他地方,看起来应该是
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);
}
答案 1 :(得分:0)
// 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);
在尝试之前,您应该了解自己要做的事情。 通过PHP / MySQL的一些基本tutorial来帮助您理解基础知识。