gpt4 book ai didi

PHP/MySQL : why my query doesn't work?

转载 作者:行者123 更新时间:2023-11-29 07:36:33 25 4
gpt4 key购买 nike

我在 cloud9 上有一个 Web 项目,我可以使用 Mysqli 命令插入 MySQL 中的数据库。但是当我尝试从数据库中选择数据时,我的查询不起作用:( echo $result 不打印任何内容)。有什么想法吗?

也许使用 PDO 命令更好?

    <?php

//connect
$servername = getenv('IP');
$username = getenv('C9_USER');
$password = "";
$database = "myproject";
$dbport = 3306;

// Create connection
$bdd = new mysqli($servername, $username, $password, $database, $dbport);


// Check connection
if ($bdd->connect_error) {
die("Connection failed: " . $bdd->connect_error);
}
echo "Connected successfully (".$bdd->host_info.")";
$pseudonyme = $_POST['pseudo'];
$mot_de_passe = $_POST['mdp'];
$confirm_mdp = $_POST['confirm_mdp'];
$email = $_POST['email'];

if($mot_de_passe == $confirm_mdp)
{

$mot_de_passe = crypt($mdp);
$pseudonyme = htmlspecialchars($Pseudonyme);

//verifying is user mail is already in base

$reqVerif = $bdd->prepare('SELECT ID_utilisateur FROM utilisateurs WHERE Adresse_email = ?');
$reqVerif->bind_param("sss",$email);
$reqVerif->execute();
$result = $reqVerif->fetch();

//user already exist in DB
if($result)
{
?>
<div class="nouveau_membre" >
<p>You already have a account...</p>
</div>
<?php
}
else
{
//in case of new user
$req = $bdd->prepare('INSERT INTO utilisateurs(Pseudonyme, Mot_de_passe, Adresse_email, Date_inscription) VALUES(?, ?, ?, CURDATE())');
$req->bind_param("sss", $pseudonyme, $mot_de_passe, $email);
$req->execute();
?>

<div class="nouveau_membre" >
<p>New USER !</p>
</div>
<?php
}
}
?>

最佳答案

您仅绑定(bind)电子邮件参数,不需要 3 个“s”

$reqVerif->bind_param("sss",$email);

尝试:

$reqVerif->bind_param("s",$email);

关于PHP/MySQL : why my query doesn't work?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30631557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com