Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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 将mySQL结果显示到文本框_Php_Mysql - Fatal编程技术网

Php 将mySQL结果显示到文本框

Php 将mySQL结果显示到文本框,php,mysql,Php,Mysql,我试图从mySQL数据库中选择用户电子邮件,然后在文本框中显示结果。但是,我收到一条错误消息: htmlentities()要求参数1为字符串,数组给定 <?php if(!isset($_SESSION)){ session_start(); } include "config.php"; $q = "SELECT email FROM users WHERE id ='" . $_SESSION['id'] . "'"; $

我试图从mySQL数据库中选择用户电子邮件,然后在文本框中显示结果。但是,我收到一条错误消息: htmlentities()要求参数1为字符串,数组给定

<?php

    if(!isset($_SESSION)){
        session_start();
    }

    include "config.php";

    $q = "SELECT email FROM users WHERE id ='" . $_SESSION['id'] . "'";
    $result = $sql->query($q);
    $user_email = $result->fetch_assoc();

    $link->close();

?>

    <input class="form" type="text" name="email" value="<?php echo html entities($user_email); ?>" />

因为结果是数组而不是字符串。您可以做什么:

<?php

    if(!isset($_SESSION)){
        session_start();
    }

    include "config.php";

    $q = "SELECT email FROM users WHERE id ='" . $_SESSION['id'] . "'";
    $result = $sql->query($q);
    $user_email = $result->fetch_assoc();

    $resultText = '';
    $glue = '</br>' . PHP_EOL;
    foreach($user_email as $email) {
        $resultText .= $email . $glue;
    }

    $link->close();

?>

    <input class="form" type="text" name="email" value="<?php echo htmlentities($resultText); ?>" />


fetch_assoc
返回行

尝试:


您的代码易受SQL注入攻击。你应该使用事先准备好的陈述。
$user_email['enter_the_mysql_field_name_here']