如果有人尝试按下按钮时任何字段为空,我想显示一条错误消息,但是当我将字段保留为空时,什么也没有发生,表单只是添加到具有空字段的数据库中。
所以我想知道代码有什么问题,删除或更改了哪些内容。
<?php
$servername ="localhost";
$username = "root";
$password = "";
$db = mysqli_connect("localhost", "root", "");
$db->select_db('hgeza06');
$mysqli = mysqli_connect($servername, $username, $password);
/*
$con = mysqli_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysqli_error());
} else {
echo "Succes!";
}
*/
mysqli_select_db( $mysqli ,"hgeza06");
if (isset($_POST['submit']))
{
$address = mysqli_real_escape_string($mysqli, $_POST['address']);
$password = md5(mysqli_real_escape_string($mysqli,$_POST['password']));
$password1 = md5(mysqli_real_escape_string($mysqli,$_POST['password1']));
$sql = "INSERT INTO cegek(Email, Password)VALUES('$address', '$password')";
$result = mysqli_query( $mysqli,$sql) or trigger_error(mysqli_error($mysqli));
if(empty($_POST['address'])){
echo "Email is required!";
}
if(empty($_POST['password'])){
echo "Password is required!";
}
if(empty($_POST['password1'])){
echo "Password is required!";
}
header("location: http://localhost/phptest/reg/reg.php");
exit;
}
?>