即使数据库中存在数据,SQL也会返回空行

时间:2018-11-18 06:38:32

标签: php html mysql phpmyadmin

所以我有一个会话变量,该变量从登录名中获取信息,并希望通过该变量显示数据。我尝试了任何方法,但是始终返回null。数据存储在phpmyadmin中,但是当我运行sql查询时在phpmyadmin中,它再次返回null。

php:

<?php

$host="localhost";
$user="root";
$password="";
$db="bhprj";
session_start();

$con=mysqli_connect($host,$user,$password,$db);
$var =  $_SESSION['en'];
$sql = "select * from PB where mailid = '{$_SESSION['en']}';";
$res=mysqli_query($con,$sql);
$result=mysqli_fetch_assoc($res);
<div class="input-field">
    <p>SOURCE</p><br> 
    <input type="text" name="sn" value="<?php echo $result['source']; ?>" required>
</div>
<div class="input-field">
    <p> destination </p> <br>
    <input type="text" name="dn" value="<?php echo $result['destination']; ?>" required>
</div>
<div class="input-field">
    <p>NO OF PASSENGERS </p><br><br> 
    <input type="number" name="nn" value="<?php echo $result['nop']; ?>" required>
</div>

<div class="input-field">
    <p>DATE</p><br><br> 
    <input type="date" name="date" value="<?php echo $result['date']; ?>" required>
</div>

希望获得帮助。

1 个答案:

答案 0 :(得分:0)

尝试这样编写SQL查询:

$sql = "select * from PB where mailid = ". {$_SESSION['en']};