【问题标题】:Notice: Array to string conversion in error when requesting data from a databse注意:从数据库请求数据时,数组到字符串的转换出错
【发布时间】:2014-01-07 12:32:37
【问题描述】:

我环顾四周,找不到问题的答案。 我试图从数据库中获取一行,但它只是给我一个通知说:

注意:/xampp/...中的数组到字符串的转换...

这是我的代码:

$sql6 = mysql_query("SELECT * FROM replies WHERE thread_id = $thread_id");
    $numRows = mysql_num_rows($sql6);
    $replies = '';
    if ($numRows < 1) {
        $replies =  "There are no replies yet, you can make the first!";
    } else {
        while ($rows = mysql_fetch_array($sql6)) {
            $reply_content = $rows[5];
            $reply_username = $rows[7];
            $reply_date = $rows[8];
            $reply_author_id = [4];

            $sql9 = mysql_query("SELECT * FROM users WHERE id = $reply_author_id");
            $numRows = mysql_num_rows($sql); 
            if ($numRows < 1) {
                while ($rows = mysql_fetch_array($sql)) {
                    $reply_user_fn = $rows['first_name'];
                    $reply_user_ln = $rows['last_name'];
                    $reply_user_id = $rows['id'];
                    $reply_user_pp = $rows['profile_pic'];
                    $reply_user_lvl = $rows['user_level'];
                    $reply_user_threads = $rows['threads'];
                    $reply_user_email = $rows['email'];


                    }
                }
            }
        }

请帮助我。我对 PHP 还很陌生,我看不出我做错了什么。

【问题讨论】:

  • 错误是指哪个行号?
  • 这一行是错字吗? $reply_author_id = [4];?

标签: php mysql arrays string


【解决方案1】:

错字

 $sql9 = mysql_query("SELECT * FROM users WHERE id = $reply_author_id");
 $numRows = mysql_num_rows($sql); //here $sql will be $sql9

----------------------------------- ^

 if ($numRows < 1) {
 while ($rows = mysql_fetch_array($sql)) {//here $sql will be $sql9

----------------------------------------------- --------^

正确的代码:

 $sql9 = mysql_query("SELECT * FROM users WHERE id = $reply_author_id");
 $numRows = mysql_num_rows($sql9); //here $sql will be $sql9
 if ($numRows < 1) {
 while ($rows = mysql_fetch_array($sql9)) {//here $sql will be $sql9

【讨论】:

  • 这消除了错误,但现在我收到一个新错误,表示我的 mysql 语法有错误。
【解决方案2】:

我对 PHP 也很陌生,但您的 while 比较中的代码不应该是

mysqli_fetch_array($sql6)

而不是

mysql_fetch_array($sql6)?

【讨论】:

  • 你在安全方面是正确的,但它不会给出任何错误:)
  • 啊,我明白了。我不知道。我刚刚看到我的代码有 i 而你的没有,哈哈。
猜你喜欢
  • 1970-01-01
  • 2016-08-29
  • 1970-01-01
  • 2023-03-06
  • 2017-08-11
  • 2013-04-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多