在我的网站上,我想注册一个用户。
我的 HTML 是:
<form method="post" action="register.php">
<h1>Register</h1>
<p>If you already have an account, please login</p>
<div class="styled_select">
<select name="title">
<option value="mr">Mr</option>
<option value="mrs">Mrs</option>
<option value="miss">Miss</option>
</select>
</div>
<input type="text" name="first_name" placeholder="First Name" required><br>
<input type="text" name="last_name" placeholder="Last Name" required><br>
<div class="styled_select">
<select name="sex" required>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<input type="text" name="age" placeholder="Age" required><br>
<input type="text" name="email" placeholder="Email" required><br>
<input type="text" name="zipcode" placeholder="Zipcode" required><br>
<input type="text" name="telephone" placeholder="Telephone" required><br>
<input type="checkbox" class="checkbox" required> Agree to terms and conditions. <br>
<input type="checkbox" class="checkbox" name="keep_informed"> Keep me informed on future promotions. <br>
<input type="submit" name="" value="Register" class="submit_button"><br>
</form>
我的php函数是:
class Register {
public function register($title, $first_name, $last_name, $sex, $age, $email, $zipcode, $telephone, $keep_informed) {
$title = mysql_real_escape_string($title);
$first_name = mysql_real_escape_string($first_name);
$last_name = mysql_real_escape_string($sex);
$sex = mysql_real_escape_string($age);
$email = mysql_real_escape_string($email);
$zipcode = mysql_real_escape_string($zipcode);
$telephone = mysql_real_escape_string($telephone);
$keep_informed = mysql_real_escape_string($keep_informed);
$dbh = new PDO('mysql:host=localhost;dbname=testbox_new', 'root', '');
$sql = 'insert into users (title, first_name, last_name, sex, age, email, zipcode, telephone, keep_informed)
values ("'.$title.'", "'.$first_name.'",
"'.$last_name.'", "'.$sex.'",
"'.$age.'", "'.$email.'",
"'.$zipcode.'", "'.$telephone.'",
"'.$keep_informed.'")';
if ($dbh->exec($sql)) {
return true;
} else {
return false;
}
}
}
我用以下方法调用该函数:
if (isset($_POST['title']) && isset($_POST['first_name'])
&& isset($_POST['last_name'])
&& isset($_POST['sex'])
&& isset($_POST['age'])
&& isset($_POST['email'])
&& isset($_POST['zipcode'])
&& isset($_POST['telephone'])) {
if (isset($_POST['keep_informed'])) {
$keep_informed = $_POST['keep_informed'];
} else {
$keep_informed = 0;
}
$register = new Register;
$insert = $register->register($_POST['title'], $_POST['first_name'], $_POST['last_name'], $_POST['sex'], $_POST['age'], $_POST['email'], $_POST['zipcode'], $_POST['telephone'], $keep_informed);
if ($insert == true) {
header ('location: index1.php');
} else {
echo 'somethings gone wrong';
}
}
我得到的错误如下:
Warning: Missing argument 1 for Register::register(), called in C:\xampp\htdocs\testbox\register.php on line 53 and defined in C:\xampp\htdocs\testbox\register.php on line 14
Warning: Missing argument 2 for Register::register(), called in C:\xampp\htdocs\testbox\register.php on line 53 and defined in C:\xampp\htdocs\testbox\register.php on line 14
Warning: Missing argument 3 for Register::register(), called in C:\xampp\htdocs\testbox\register.php on line 53 and defined in C:\xampp\htdocs\testbox\register.php on line 14
Warning: Missing argument 4 for Register::register(), called in C:\xampp\htdocs\testbox\register.php on line 53 and defined in C:\xampp\htdocs\testbox\register.php on line 14
Warning: Missing argument 5 for Register::register(), called in C:\xampp\htdocs\testbox\register.php on line 53 and defined in C:\xampp\htdocs\testbox\register.php on line 14
Warning: Missing argument 6 for Register::register(), called in C:\xampp\htdocs\testbox\register.php on line 53 and defined in C:\xampp\htdocs\testbox\register.php on line 14
Warning: Missing argument 7 for Register::register(), called in C:\xampp\htdocs\testbox\register.php on line 53 and defined in C:\xampp\htdocs\testbox\register.php on line 14
Warning: Missing argument 8 for Register::register(), called in C:\xampp\htdocs\testbox\register.php on line 53 and defined in C:\xampp\htdocs\testbox\register.php on line 14
Warning: Missing argument 9 for Register::register(), called in C:\xampp\htdocs\testbox\register.php on line 53 and defined in C:\xampp\htdocs\testbox\register.php on line 14
Notice: Undefined variable: title in C:\xampp\htdocs\testbox\register.php on line 16
Notice: Undefined variable: first_name in C:\xampp\htdocs\testbox\register.php on line 17
Notice: Undefined variable: sex in C:\xampp\htdocs\testbox\register.php on line 18
Notice: Undefined variable: age in C:\xampp\htdocs\testbox\register.php on line 19
Notice: Undefined variable: email in C:\xampp\htdocs\testbox\register.php on line 20
Notice: Undefined variable: zipcode in C:\xampp\htdocs\testbox\register.php on line 21
Notice: Undefined variable: keep_informed in C:\xampp\htdocs\testbox\register.php on line 22
Notice: Undefined variable: age in C:\xampp\htdocs\testbox\register.php on line 29
Notice: Undefined variable: keep_informed in C:\xampp\htdocs\testbox\register.php on line 31
有没有人知道问题是什么?我实在想不通!
任何帮助,将不胜感激 ;)
谢谢!