Php 将mySQL结果显示到文本框
我试图从mySQL数据库中选择用户电子邮件,然后在文本框中显示结果。但是,我收到一条错误消息: htmlentities()要求参数1为字符串,数组给定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'] . "'"; $
<?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']