这是我的代码
我的 if-else 语句有问题还是插入有问题
if(isset($_POST["Add"])) {
$name = $_POST["username"];
$pass = $_POST["password"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$hph = $_POST["home"];
$hp = $_POST["hp"];
$mail = $_POST["email"];
$add = $_POST["address"];
$age = $_POST["age"];
$pos = $_POST["position"];
$dept = $_POST["dept"];
$result我用它来检查我的用户名
$result=mysql_query("select*from employee where Emp_Username='$name'");
if($name==""||$pass==""||$fname==""||$lname==""||$hph==""||$hp==""||$mail==""||$add==""||$age==""||$pos==""||$dept=="")
{
?>
<script type="text/javascript">
alert("Please fill in all the required informations.");
</script>
<?php
}
elseif(empty($errors)===true)
{
if (!preg_match("/^[A-Z][a-zA-Z -]+$/i",$_POST['fname']))
{
$fnameErr= 'Invalid key has been input*';
}
if (!preg_match("/^[A-Z][a-zA-Z -]+$/i",$_POST['lname']) )
{
$lnameErr= 'Invalid key has been input*';
}
if (filter_var($mail, FILTER_VALIDATE_EMAIL) === false)
{
$mailErr = 'A valid email address is required*';
}
if (!preg_match('/^[0-9]{1,}/', $_POST['age']))
{
$ageErr = 'Only can be numeric*';
}
if (!preg_match("/^[a-zA-Z0-9 _.,:\"\']+$/i", $_POST['address']))
{
$addErr = 'Address must be letters and numbers*';
}
if (!preg_match("/^[0-9]{2,2}[-][0-9]{7,7}$/", $_POST['home']))
{
$hphErr= 'Phone must comply with this mask: 04-4XX1234*';
}
if (!preg_match("/^[0-9]{3,3}[-][0-9]{7,7}$/", $_POST['hp']))
{
$hpErr= 'Phone must comply with this mask: 014-XXX1234*';
}
if(strlen($name)<4)
{
$nameErr = 'Your username must between 4 to 12 characters*';
}
if (strlen($pass) < 6)
{
$passErr = 'Your password must be at least 6 characters*';
}
}
elseif(mysql_num_rows($result)==0)
if $result==0 所以我的数据将插入到员工表中,但它不能工作
{
mysql_query("insert into employee(Dept_ID, Emp_Address, Emp_Age, Position, Emp_Username, Emp_Password, Emp_Fname, Emp_Lname, ContactNo_Home, ContactNo_HP, Emp_Email)
values('$dept','$add','$age','$pos','$name','$pass','$fname','$lname','$hph','$hp','$mail')");
?>
<script type="text/javascript">
alert('Registered successfully!');
</script>
<?php
}
else
{
?>
<script type="text/javascript">
alert("Username already in use!");
</script>
<?php
}
}
希望有人可以帮助我找出问题并解决它。谢谢!