Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php函数中sql查询中的False值仅适用于quotationmarks_Php_Mysql_Sql_Web - Fatal编程技术网

php函数中sql查询中的False值仅适用于quotationmarks

php函数中sql查询中的False值仅适用于quotationmarks,php,mysql,sql,web,Php,Mysql,Sql,Web,我必须开发一个appStore插件,但一个查询无法正常工作 功能 function addItem($installed){... function addItem($installed ) { $servername = "localhost"; $username = "root"; $password = ""; $dbname = "appmarket"; // Create connection $conn = mysqli_connect($ser

我必须开发一个appStore插件,但一个查询无法正常工作

功能

function addItem($installed){...
function addItem($installed )
{
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "appmarket";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}



/*if($installed == true){
    $sql = "SELECT * FROM shopitems Where installed = true ";
} else if ($installed == false){
    $sql = "SELECT * FROM shopitems Where installed = false ";
}else{
    error_log("forgot to enter installed bool");
}*/

$sql = "SELECT * FROM shopitems Where installed = ". $installed ;

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo'<div id="1" class="blockItem order2"> <!-- this div contains an Table for the Content of the downloadabel app-->
    <div>
        <table id=itemTable style="table-layout:fixed"><!--this table contains the header and the version number-->
            <tr>
                <th id="itemHeader" class="itemheader"><h2>' . $row["Header"] . '</h2></th>
                <td id="itemAppVersion" class="version">' . $row["Version"] . '</td>
            </tr>

        </table>
        <table id=itemTable style="table-layout:fixed"><!--this table contains the image and the description-->

            <tr class="tableformat">
                <td id="itemAppThumbnail" width="120px">
                    <img class="itemThumbnail" src="Images/' . $row["Imageurl"] . '">
                </td>
                <td id="itemAppDescription" style="width: 200px;">
                <a class="whiteAnchor" href="Downloadable/' . $row["Downloadurl"] . '" download="logo">
                    ' . $row["Content"] . '
                </a>
                </td>
            </tr>
        </table>
    </div>
</div>'
;
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
}



?>
通过回显将商店项目(一些html内容)添加到div中

<div class="flexRow order2 topLine">
    <?php 
       addItem("false");
    ?>
</div>
我的问题: 正如您所看到的,伪布尔值位于quotationmarks中。否则就不行了。truestatement可以是引号,也可以不是引号。我的问题出了什么问题吗

“installed”列来自布尔值

php在网站上显示的警告如下:

$sql = "SELECT * FROM shopitems Where installed = ". $installed ;
mysqli_num_rows()要求参数1为mysqli_结果,布尔值 在第31行的C:\xampp\htdocs\setupItems.php中给出

0结果

第31行至第33行:

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {

<?php       
if(mysqli\u num\u行($result)>0){
//每行的输出数据
while($row=mysqli\u fetch\u assoc($result)){

问题源于未使用参数化语句和未检查数据类型

仅供参考,您应该查看

echo true;
哪个打印“1”

什么也不印

现在,在您的例子中,您尝试将布尔值连接到字符串。这是不可能的,因此PHP隐式地尝试将布尔值转换为字符串本身,就像它对echo所做的那样。 在本例中,false不是强制转换为
“false”或
“0”
,而是转换为
,这将导致您的查询为:

"SELECT * FROM shopitems Where installed = "
这是无效的SQL

作为快速修复,您可以使用

"SELECT * FROM shopitems Where installed = ". ($installed?"1":"0")
它明确地将布尔值“强制转换”为“0”,并生成有效的查询。 从长远来看,您应该研究

要了解更多信息,您还应该看看

请展示您的完整函数
addItem()
作为答案@franzgleichman(当然有一点mroe细节)您是说PaMaterialized thank you.这似乎是逻辑。对php来说只是一个新手…但实际上我并没有重复bool值?!还是我?我调用了addItem函数在index.php上,该函数回显html代码(参见上文,我编辑了该问题)。但是查询通常会出现在函数的文件中。不,您不会回显它们。我只是将它们包含进来以演示代码失败的原因。好的,我知道我理解这是因为我将其添加到字符串中。感谢您的努力!我使用了。($installed?:“0”)知道。
"SELECT * FROM shopitems Where installed = "
"SELECT * FROM shopitems Where installed = ". ($installed?"1":"0")