我在 php 中的查询不起作用。
当布尔值:$alles_goed=true;
那么它应该运行查询。但事实并非如此。在 php 文件中,一切都很好,但是当我尝试在 mysql 中对其进行测试时,它没有显示任何内容。
这是我的代码:
$mysqli = new mysqli("localhost", "root", "usbw", "accounts");
$resultaat='';
$username='';
$password='';
$email='';
$age='';
$alles_goed=false;
if (isset($_POST['username'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$age = $_POST['age'];
$alles_goed=true;
echo'<div class="error">';
if (substr_count($email, '@')<1){
echo'Geen geldig emailadress<br>';
$alles_goed=false;
}
if ($username==''){
echo 'Geen naam ingevuld</br>';
$alles_goed=false;
}
if ($password==''){
echo 'Geen tekst ingevuld</br>';
$alles_goed=false;
}
echo '</div> ';
if ($alles_goed==true){
$veld1 = $mysqli->real_escape_string($username);
$veld2 = $mysqli->real_escape_string($password);
$veld3 = $mysqli->real_escape_string($email);
$resultaat = $mysqli->query("INSERT INTO account_information (username, password, email) VALUES ('" . $veld1 . "','" . $veld2 . "', '".$veld3 ."')");
var_dump($resultaat);
}
在这部分代码中,它显示:“我们已将验证链接发送到您的电子邮件”。$resultaat
那么是不是问题?
if ($resultaat == false)
{
echo "Query mislukt. Foutmelding: " . $mysqli->error;
}
else
{
var_dump($mysqli->insert_id);
echo"We have sent an verification link to your email";
}
我还使用检查来检查我是否连接到数据库并且它没有给出错误。:
if($mysqli->connect_error>0){
echo 'ERROR' . $mysqli->connect_error;
}
if ($mysqli->connect_errno >0) {
echo "er is iets fout";
}
if (mysqli_connect_errno())
{
printf("Er kan geen verbinding worden gemaakt met de database. Foutmelding: %s\n", mysqli_connect_error());
}
感谢您的时间。