最佳答案 这在我的本地系统中运行良好: 根据您的要求尝试此代码-6ren">
gpt4 book ai didi

php - 从 MySql 数据库中获取值到表单中

转载 作者:行者123 更新时间:2023-11-29 03:31:14 25 4
gpt4 key购买 nike

我正在尝试从 MySql 数据库中获取值。我有一个表单,我想从 MySql 数据库中获取 emailid。请帮忙

<tr><td><b>Email :</td><td><input type="text" name="txtemail" readonly value="<?php
$name=$_SESSION['usr_name'];
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name

$conn=mysqli_connect($host,$username,$password) or die("cannot connect");

mysqli_select_db($conn,$db_name);

$result = mysqli_query($conn,"SELECT emailid FROM tabledetails WHERE
username='$name'");

echo $result;
mysqli_close($conn);
?>">
</td>
</tr>

最佳答案

这在我的本地系统中运行良好:

根据您的要求尝试此代码:

<?php
$name=$_SESSION['usr_name']
$servername="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$dbname="test"; // Database name
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else{
echo "Connected successfully";
}

$res = mysqli_query($conn,"SELECT emailid FROM tabledetails WHERE username='$name'");

while($row=mysqli_fetch_assoc($res))
{
$rows = $row['email'];
print_r $rows;
echo $rows;
}
?>
<tr><td><b>Email :</td><td><input type="text" name="txtemail" readonly value="<?php echo $rows ?>"/>

输出:-

Connected successfully
Email :User

关于php - 从 MySql 数据库中获取值到表单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30256639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com