Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
基于if语句PHP检查MySQL列内容插入_Php_Mysql_Curl - Fatal编程技术网

基于if语句PHP检查MySQL列内容插入

基于if语句PHP检查MySQL列内容插入,php,mysql,curl,Php,Mysql,Curl,这段代码正在检查我的sql server中“Location”列的内容,若内容是“inside”,则应该将其更改为“outside”,反之亦然。然后,它将字符串“外部/内部”发送到sendText方法,该方法将利用文本消息中的响应 问题是服务器中没有数据被更改,连接没有错误,因此它连接良好,但无法插入数据库 在运行这个PHP文件时,除了OutputReturnCode 1之外,我没有得到任何反馈——但这是来自curl实现的,它告诉我文本没有发送 感谢您的帮助, 干杯 问题是服务器中没有数据被更改

这段代码正在检查我的sql server中“Location”列的内容,若内容是“inside”,则应该将其更改为“outside”,反之亦然。然后,它将字符串“外部/内部”发送到sendText方法,该方法将利用文本消息中的响应

问题是服务器中没有数据被更改,连接没有错误,因此它连接良好,但无法插入数据库

在运行这个PHP文件时,除了OutputReturnCode 1之外,我没有得到任何反馈——但这是来自curl实现的,它告诉我文本没有发送

感谢您的帮助, 干杯

问题是服务器中没有数据被更改,连接没有错误,因此它连接良好,但无法插入数据库

这是因为代码中没有
mysqli\u query()

解决方案

        $con = mysqli_connect($host,$uname,$opw,$odb);  //database login details
        // Check connection
        if (mysqli_connect_errno())                                             //if you cannot access the database
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();         //useful error message
          }

        $result = mysqli_query($con,"SELECT * FROM PetLoc");

        if (!$result) { // add this check.
            die('Invalid query: ' . mysqli_error());
        }

        while($row = mysqli_fetch_assoc($result))
        {
             if($row['Location'] == 'inside')
             {
               $sql = ("INSERT INTO PetLoc (Location) VALUES ('outside')");
               sendText("outside");
             }
             else
             {
                $sql =("INSERT INTO PetLoc (Location) VALUES ('inside')");
               sendText("inside");
             }
        }

    function sendText($petLoc) {  
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "smsserver");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, true);
        $data = array(
             'mphone' => 'phoneno',
             'smstext' => 'Your pet walked through the door flap, it was last seen '.$petLoc.'.',
             'username' => 'uname'
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        curl_close($ch);
        echo "Output".$output ;

    }
mysqli_close($con);
问题是服务器中没有数据被更改,连接没有错误,因此它连接良好,但无法插入数据库

这是因为代码中没有
mysqli\u query()

解决方案

        $con = mysqli_connect($host,$uname,$opw,$odb);  //database login details
        // Check connection
        if (mysqli_connect_errno())                                             //if you cannot access the database
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();         //useful error message
          }

        $result = mysqli_query($con,"SELECT * FROM PetLoc");

        if (!$result) { // add this check.
            die('Invalid query: ' . mysqli_error());
        }

        while($row = mysqli_fetch_assoc($result))
        {
             if($row['Location'] == 'inside')
             {
               $sql = ("INSERT INTO PetLoc (Location) VALUES ('outside')");
               sendText("outside");
             }
             else
             {
                $sql =("INSERT INTO PetLoc (Location) VALUES ('inside')");
               sendText("inside");
             }
        }

    function sendText($petLoc) {  
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "smsserver");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, true);
        $data = array(
             'mphone' => 'phoneno',
             'smstext' => 'Your pet walked through the door flap, it was last seen '.$petLoc.'.',
             'username' => 'uname'
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        curl_close($ch);
        echo "Output".$output ;

    }
mysqli_close($con);