这是我的注册码,但我不知道问题是什么。编译器显示错误是“教师”选择部分。
我检查过每一个标签,我认为这是正确的。我试图删除PHP部分,语法错误消失了。我猜错误是存在的,但为什么Dreamweaver编译器会显示“教师”部分呢?
<?php
mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_database('db') or die(mysql_error());
if (isset($_POST['submit'])) {
$myusername = strtolower($_POST['username']);
$name = strip_tags($_POST['name']);
$mypassword = strip_tags($_POST['password']);
$password1 = strip_tags($_POST['password1']);
$role = strip_tags($_POST['role']);
$gender = strip_tags($_POST['gender']);
$matric = strip_tags($_POST['matric']);
$college = strip_tags($_POST['college']);
$faculty = strip_tags($_POST['faculty']);
$course = strip_tags($_POST['course']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$errors = array();
if (empty($myusername) || empty($name) || empty($mypassword) || empty($password1)
|| empty($role) || empty($gender) || empty($matric) || empty($college)
|| empty($faculty) || empty($course) || empty($email) || empty($phone)) {
$errors[] = 'Please fill in <b>*ALL*</b> fields! <a href="registration.php">Back</a>';
} else {
if ($mypassword != $password1) {
$errors[] = 'Password does not match';
}
if (strlen($myusername) > 30) {
$errors[] = "Length of username is exceed <b>MAX</b> limit! Must be less than 30 characters";
}
if (strlen($mypassword) > 25 || strlen($password) < 6) {
$errors[] = "Password must be between 6 to 20 characters. <a href='registration.php'>Back</a>";
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br/>';
}
} else {
mysql_query("INSERT INTO student (username, name, password, role, gender, matric, college, faculty, course, email, phone) VALUES ('" . $myusername . "', '" . $name . "', '" . $mypassword . "','" . $role . "','" . $gender . "','" . $matric . "','" . $college . "','" . $faculty . "','" . $course . "','" . $email . "','" . $phone . "')");
echo "<strong>You're SUCCESSFULLY registered! You are now one of the volunteers</strong> You can now <a href= 'index.php'>Login</a> here!.";
exit();
}
} else {
?>
<tr>
<td bgcolor="orange">
<table cellpadding='0' cellspacing='0' border='0' width='100%'>
<tr>
<td bgcolor="orange" align=center style="padding:2;padding-bottom:4">
<font size=-1 color="white" face="verdana,arial">
<b>Registration Form</b></font></th>
</tr>
<tr>
<td bgcolor="white" style="padding:5"><br>
<form method="post" action="index.php" name="registration_form" target="_top">
<center>
<table>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Username </font></td>
<td><input type="text" name="username" size="60"></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Name</font></td>
<td><input type="text" name="name" size="60"></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Password </font></td>
<td><input type="password" name="password" size="60"></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Verify Password </font></td>
<td><input type="password" name="password1" size="60"></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Role</font></td>
<td><select name="role">
<option value="student">Student</option>
</select></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Gender</font></td>
<td><select name="gender">
<option value="male">Male</option>
<option value="female">Female</option>
</select></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Matric </font></td>
<td><input type="text" name="matric" size="60"></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>College </font></td>
<td><select name="college">
<option value="a">A College</option>
<option value="b">B Residential College</option>
<option value="c">C Campus</option>
</select></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Faculty </font></td>
<td><select name="faculty">
<option value="ABC">ABC</option>
<option value="XYZ">XYZ</option>
</select></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Course </font></td>
<td><input type="text" name="course" size="60"></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Email </font></td>
<td><input type="text" name="email" size="60"></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Phone Number </font></td>
<td><input type="text" name="phone" size="60"></td>
</tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1></font></td>
<td><font face="verdana,arial">
<input type="submit" name="Submit" value="Submit">
</font>
<input type="reset" name="reset" value="Reset"></td>
</tr>
<tr>
<td colspan=2><font face="verdana,arial" color="black" size=-1> </font></td>
</tr>
</table>
答案 0 :(得分:1)
您没有关闭其他括号,mysql_select_db()
也不是mysql_select_database()
的函数。
使用此代码。
<?php
$con=mysql_connect('localhost', 'root', '') or die (mysql_error());
mysql_select_db('db',$con) or die (mysql_error());
if (isset($_POST['submit'])){
$myusername=strtolower($_POST['username']);
$name=strip_tags($_POST['name']);
$mypassword=strip_tags($_POST['password']);
$password1=strip_tags($_POST['password1']);
$role=strip_tags($_POST['role']);
$gender=strip_tags($_POST['gender']);
$matric=strip_tags($_POST['matric']);
$college=strip_tags($_POST['college']);
$faculty=strip_tags($_POST['faculty']);
$course=strip_tags($_POST['course']);
$email=strip_tags($_POST['email']);
$phone=strip_tags($_POST['phone']);
$errors = array();
if (empty($myusername) || empty($name) || empty($mypassword)
||empty($password1) || empty($role) || empty($gender) || empty($matric) || empty($college) || empty($faculty) || empty($course) || empty($email) || empty($phone)){
$errors[]= 'Please fill in <b>*ALL*</b> fields! <a href="registration.php">Back</a>';
}
else{
if ($mypassword!=$password1){
$errors[] = 'Password does not match';
}
if (strlen($myusername)>30){
$errors[] = "Length of username is exceed <b>MAX</b> limit! Must be less than 30 characters";
}
if (strlen($mypassword)>25 || strlen($password)<6){
$errors[]= "Password must be between 6 to 20 characters. <a href='registration.php'>Back</a>";
}
}
if(!empty($errors)){
foreach($errors as $error){
echo $error, '<br/>';
}
}
else{
mysql_query("INSERT INTO student (username, name, password, role, gender, matric, college, faculty, course, email, phone) VALUES ('".$myusername."', '".$name. "', '" .$mypassword. "','" .$role. "','".$gender."','". $matric."','".$college."','".$faculty."','".$course."','".$email."','".$phone."')");
echo "<strong>You're SUCCESSFULLY registered! You are now one of the volunteers</strong> You can now <a href= 'index.php'>Login</a> here!.";
exit();
}
}
else{
?>
<tr><td bgcolor="orange"><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr>
<td bgcolor="orange" align=center style="padding:2;padding-bottom:4">
<font size=-1 color="white" face="verdana,arial">
<b>Registration Form</b></font></th></tr>
<tr><td bgcolor="white" style="padding:5"><br>
<form method="post" action="index.php" name="registration_form" target="_top">
<center>
<table>
<tr><td><font face="verdana,arial" color="black" size=-1>Username </font></td>
<td><input type="text" name="username" size="60"></td></tr>
<tr><td><font face="verdana,arial" color="black" size=-1>Name</font></td>
<td><input type="text" name="name" size="60"></td></tr>
<tr><td><font face="verdana,arial" color="black" size=-1>Password </font></td>
<td><input type="password" name="password" size="60"></td></tr>
<tr><td><font face="verdana,arial" color="black" size=-1>Verify Password </font></td>
<td><input type="password" name="password1" size="60"></td></tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Role</font></td><td><select name="role">
<option value="student">Student</option>
</select></td></tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Gender</font></td>
<td><select name="gender">
<option value="male">Male</option>
<option value="female">Female</option>
</select></td>
</tr>
<tr><td><font face="verdana,arial" color="black" size=-1>Matric </font></td>
<td><input type="text" name="matric" size="60"></td></tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>College </font></td>
<td><select name="college">
<option value="a">A College</option>
<option value="b">B Residential College</option>
<option value="c">C Campus</option>
</select></td></tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1>Faculty </font></td>
<td><select name="faculty">
<option value="ABC">ABC</option>
<option value="XYZ">XYZ</option>
</select></td></tr>
<tr><td><font face="verdana,arial" color="black" size=-1>Course </font></td>
<td><input type="text" name="course" size="60"></td></tr>
<tr><td><font face="verdana,arial" color="black" size=-1>Email </font></td>
<td><input type="text" name="email" size="60"></td></tr>
<tr><td><font face="verdana,arial" color="black" size=-1>Phone Number </font></td>
<td><input type="text" name="phone" size="60"></td></tr>
<tr>
<td><font face="verdana,arial" color="black" size=-1></font></td>
<td><font face="verdana,arial">
<input type="submit" name="Submit" value="Submit">
</font>
<input type="reset" name="reset" value="Reset"></td>
</tr>
<tr>
<td colspan=2><font face="verdana,arial" color="black" size=-1> </font></td>
</tr>
</table>
</center>
</form>
<?php }?>
答案 1 :(得分:0)
在服务器中尝试...然后给出结论。解释时,Dreamweaver很多次都错了。它在javascript解释时给出了很多次错误。你可以尝试任何wamp或灯服务器。