Mysql SQL找不到任何值
我在返回sql行的值时遇到问题,我的sql请求在控制台上运行良好,但在代码中无法返回一行,有什么帮助吗?谢谢Mysql SQL找不到任何值,mysql,Mysql,我在返回sql行的值时遇到问题,我的sql请求在控制台上运行良好,但在代码中无法返回一行,有什么帮助吗?谢谢 <?php require_once 'sql.php'; $sqlConnexion = new mysqli($hn,$un,$pw,$db); if($sqlConnexion->connect_error){ die ('Soucis de connexion SQL');} $date = date("d/m/y G:i:s"); if(isset($_POST[
<?php
require_once 'sql.php';
$sqlConnexion = new mysqli($hn,$un,$pw,$db);
if($sqlConnexion->connect_error){
die ('Soucis de connexion SQL');}
$date = date("d/m/y G:i:s");
if(isset($_POST['zoneDeText'])){
$area = $_POST['zoneDeText'];
$queryone= "SELECT SortieTraitée FROM entry WHERE entréesUtilisateurs=?";
$instruction = $sqlConnexion->prepare($queryone);
if(!$instruction->prepare($queryone)){
echo "$instruction->errno";
}else{
$instruction->bind_param('s', $area);
$instruction->execute();
$result = $instruction->get_result();
while ($row = $result->fetch_array(MYSQLI_NUM)){
foreach ($row as $out){
if($out == $area){
echo $out;
}elseif($out != $area){
echo 'Still not found';
}
}
}
$instruction->close();
}
?>
实际上,您不打印任何内容,只返回值,除非代码在函数中,否则没有意义
if($out == $area){
return $out;
}
文件说:
如果从主脚本文件中调用return,则脚本执行结束
除非上面显示的代码已经包含在另一个PHP脚本中,否则这意味着它将结束脚本而不输出任何内容
您的脚本还有其他一些令人困惑的地方,但上面的内容可能是您所问问题的直接原因
下面是我如何编写此代码:
if (isset($_POST['zoneDeText'])) {
$area = $_POST['zoneDeText'];
$queryone = "SELECT SortieTraitée FROM entry WHERE entréesUtilisateurs=?";
$instruction = $sqlConnexion->prepare($queryone);
// if the prepare fails, it is false
if ($instruction === false) {
// false is not an object, it has no error attribute
// the error is an attribute of the connection
die($sqlConnexion->error);
}
$instruction->bind_param('s', $area);
$instruction->execute();
$result = $instruction->get_result();
// if there are zero rows in the result, the while loop
// will finish before it starts, so there will be no output
// so first check for a result of zero rows in the result
if ($result->num_rows == 0) {
echo("Found zero rows");
} else {
while ($row = $result->fetch_assoc()) {
echo $row["SortieTraitée"];
}
}
$instruction->close();
}
选择entréesUsiliateurs=?“从输入”无法显示正确的结果。where子句发生了什么事?nothing标记专门指的是VB.Net nothing值。这里的标签有特定的含义。请不要只是随机添加它们,因为它们的单词看起来很熟悉。使用前请阅读标签说明,确保其正确。如果您仍然不确定,请不要使用它,如果需要,这里会有人为您添加它。在询问与代码相关的问题时,为您正在使用的语言添加一个标记也很重要,您还没有这样做。请这样做。谢谢,是的,正如你所看到的,我是一个初学者=是的,返回是一个可怕的错误:但即使我用let say echo$out替换它,也不会告诉我任何原因?thank=@user2690397,请记住,传统的堆栈溢出是通过向上投票和/或将最有用的答案标记为“已接受的答案”来感谢他人。阅读