Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.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使用PHP通知垃圾邮件发送error.log?_Php_Mysql - Fatal编程技术网

如何阻止我的PHP使用PHP通知垃圾邮件发送error.log?

如何阻止我的PHP使用PHP通知垃圾邮件发送error.log?,php,mysql,Php,Mysql,我目前正在从事一个项目,需要从数据库中的3个不同表中获取一些数据,并对它们进行回送,以便在jQuery中处理结果。 我正在向我的PHP发送一个包含3个变量的GET请求。第一个用于确定需要执行哪个“命令”,另外两个用于确定需要查询哪个表和哪个行 这是我目前掌握的代码: } elseif($_GET['command']=='getpage') { $mypid = $_GET['id']; $mytable = $_GET['table']; $link = mysqli

我目前正在从事一个项目,需要从数据库中的3个不同表中获取一些数据,并对它们进行回送,以便在jQuery中处理结果。 我正在向我的PHP发送一个包含3个变量的GET请求。第一个用于确定需要执行哪个“命令”,另外两个用于确定需要查询哪个表和哪个行

这是我目前掌握的代码:

} elseif($_GET['command']=='getpage') {
    $mypid = $_GET['id'];
    $mytable = $_GET['table'];

    $link = mysqli_connect($dbserver,$userdb,$passdb,$db_typo) or die(mysqli_error($link));

    if($mytable == 'tableName1'){
        $query = 'SELECT * FROM table1 WHERE uid = "'.$mypid.'"'; //I need 6 elements from this table
    } elseif($mytable == 'tableName2'){
        $query = 'SELECT * FROM table2 WHERE uid = "'.$mypid.'"'; //I need 7 elements from this table
    } elseif($mytable =='tableName3'){
        $query = 'SELECT * FROM table3 WHERE uid = "'.$mypid.'"'; //I need 8 elements from this table
    } else {
        echo 'no such table supported for this command';
    }

    $result = mysqli_query($link, $query) or die(mysqli_error($link));

    $pagecontent = array();
    while($row = mysqli_fetch_assoc($result)){
        $pagecontent[] = array(
            'id' => utf8_encode($row['uid']),
            'name' => utf8_encode($row['name']),
            'text1' => utf8_encode($row['text1']), //not every table has this
            'text2' => utf8_encode($row['text2']),
            'img' => utf8_encode($row['image']),
            'parent' => utf8_encode($row['parent']), //not every table has this
            'sub_parent' => utf8_encode($row['sub_parent']), //not every table has this
            'deleted' => utf8_encode($row['deleted'])
        );
    }

    echo '{"content": '.json_encode($pagecontent).'}';
}
我有超过50页,我需要从数据库中获取。因此,当我让发送GET请求的jQuery函数运行时,我会用

PHP注意:未定义索引:第171行/var/www/my.PHP中的text1

这是我不想要的


除了将查询和while循环放在if语句中之外,还有其他方法可以解决这个“问题”吗?

我不知道为什么不希望if检查索引,但您可以在
while
中添加另一个循环

并添加这些变量:

while($row = mysqli_fetch_assoc($result)){
    $temp = array();
    foreach($row as $key => $value) {
        $temp[$key] = utf8_encode($value);
    }
    $pagecontent[] = $temp;
    // $pagecontent[] = array_map('utf8_encode', $row);
}

echo json_encode(array('content' => $pagecontent));
这只是简单地获取
$row
中的所有内容,对所有值进行编码,然后将其推送到容器中


旁注:不要手工构建JSON字符串,创建最终的数组结构,然后在最后进行编码。

添加一个检查数组键是否存在

'text1' => isset($row['text1']) ? utf8_encode($row['text1']) : '',

在每个表中添加列
text1
,即使它是空的。@Daan我只能访问我的php文件。为什么不检查索引测试的条件?@docratie这些表是自动创建的。如果我将它们放在一起,我的项目将无法运行。为什么不检查表中是否存在该字段,然后允许该值。。