我有一个PHP函数,可以在将数据插入数据库之前检查它们。 现在,无论我在哪里调用函数,我都会在我的php函数中显示消息。例如:div。 我希望代替div中的小消息,有一个显示消息的消息框。我怎样才能做到这一点?感谢
if($u_l_name == $dbuser_last_name and $u_name == $dbuser_first_name)
{
echo "Record Exists Already";
}
else
{
$stmt2 = $this->link->prepare("INSERT INTO employers (user_password, user_first_name, user_last_name, user_DOB, user_address, user_email, user_phone, user_gender, user_position, user_contract_type, user_contract_hours) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
$stmt2->bind_param("ssssssssssi", $u_password, $u_name, $u_l_name, $u_DOB, $u_address, $u_email, $u_phone, $u_gender, $u_position, $u_contract_type, $u_contract_hours);
$stmt2->execute();
$stmt2->close();
echo "Record Added Succesfully";
}
函数调用:
<?php
if(isset($_POST['submitButton']))
{
$admin_query->addEmployerData($u_password, $u_name, $u_l_name, $u_DOB, $u_address, $u_email, $u_phone, $u_gender, $u_position, $u_contract_type, $u_contract_hours);
}
?>
答案 0 :(得分:0)
您的意思是Javascript alert方法吗?如果是,你可以这样做:
$message;
if($u_l_name == $dbuser_last_name and $u_name == $dbuser_first_name)
{
$message = "Record Exists Already";
}
else
{
$stmt2 = $this->link->prepare("INSERT INTO employers (user_password, user_first_name, user_last_name, user_DOB, user_address, user_email, user_phone, user_gender, user_position, user_contract_type, user_contract_hours) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
$stmt2->bind_param("ssssssssssi", $u_password, $u_name, $u_l_name, $u_DOB, $u_address, $u_email, $u_phone, $u_gender, $u_position, $u_contract_type, $u_contract_hours);
$stmt2->execute();
$stmt2->close();
$message = "Record Added Succesfully";
}
echo "<script>alert('$message')</script>";