我有以下问题:
我用我的login.php开始一个会话.. bla bla ..
现在我在索引上,例如以[email protected]登录
<?php
session_start();
?>
<?php
if(!isset($_SESSION["email"]))
{
echo "Please <a href=\"login.html\">login</a> first";
exit;
}
?>
现在,我要选择登录帐户的名称:
我尝试过类似的方法,但是没有用
$email = $_SESSION['email'];
$thename = mysql_query("SELECT name FROM login WHERE email LIKE '$email' LIMIT 1");
之后,我想将其添加到<“ input”>
Name: <input type="text" name="name" id="name" placeholder="Your Name" value="<?php echo $thename; ?>" style="width:calc(100% - 5px);" />
谢谢你的帮忙 :)
提姆
好吧,只要我能看到您尚未对数据库执行任何SQL查询。您需要连接到数据库并获取结果(代码是免注入的):
// You can skip this part if you've already connected to MySQL
$link = new mysqli($host, $username, $password);
$link->select_db($db_name);
// Prepare query
$sql = $link->prepare('SELECT name FROM login WHERE email = ? LIMIT 1');
// Bind the param
$sql->bind_param('s', $email);
// Execute the query
$sql->execute();
$sql->bind_result($thehome);
$sql->close();
$link->close(); // of course if you need the connection open, just remove this line
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句