这是我的代码
我的if-else语句是否出现问题或插入是否有任何问题
如果(isset($ _ POST [ “添加”])) {
$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)
如果$ result == 0,那么我的数据将插入到employee表中,但它无法正常工作
{
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
}
}
希望有人可以帮助我找出问题并解决问题。 谢谢!
答案 0 :(得分:0)
不知道您的确切架构或MySQL正在回应的错误,很难确切地说出问题所在。调试(断点,踩到等)将帮助您确定您预期的实际情况是否正在发生。
JohnnyJS提到,看起来你永远不会opened a connection到MySQL(尽管ComFreek提到这些mysql_ *函数已被弃用)。
希望这会有所帮助。祝你好运!