doufocheng6233 2016-01-03 21:24
浏览 27
已采纳

php本机到codeigniter [关闭]

I have a problem with my native php. Can you give me tips? After I login how can I view details in database like name, email, gender, username through using codeigniter?

 <?php
$con=mysqli_connect("localhost","root","","enrollmentsystem");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
            
$result = mysqli_query($con,"SELECT * FROM admin where  Username='$username'");
            
while ($row = mysqli_fetch_array($result)) {
?>
<div class="table-responsive">
  <table class=" table-hover">
    <tr class="input-lg"><td>Username:&nbsp;&nbsp;&nbsp;<br></td><td class="text-info"><?php echo $row['Username'] ?></td></tr>
    <tr class="input-lg"><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name:&nbsp;&nbsp;&nbsp;<br></td><td class="text-info"><?php echo $row['Name'] ?></td></tr>
    <tr class="input-lg"><td>&nbsp;Password:<br></td><td class="text-info"><?php echo $row['Password'] ?></td></tr>
    <tr class="input-lg"><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Email:<br></td><td class="text-info"><?php echo $row['Email'] ?></td></tr>
    <tr class="input-lg"><td>&nbsp;&nbsp;&nbsp;&nbsp;Gender:<br></td><td class="text-info"><?php echo $row['Gender'] ?></td></tr>
  </table>
</div>
<?php
}
            
mysqli_close($con);
?>

</div>
  • 写回答

1条回答 默认 最新

  • doushu0591 2016-01-03 21:46
    关注

    A few points before I begin:

    1. CodeIgniter has a built in MySQL querying class. Your current implementation of querying is prone to MySQL injection. Read more...
    2. Using the above query builder, you can get the results in many forms. Read more...
    3. You should query the database in a model, and pass the data to the view. Read more about MVC here..., and read more about passing data to views here...
    4. You should definitely start with the tutorial here which explains how to do something similar to what you want as well as other things to get you started.

    However, if you wish to continue as it is, here are some things I noticed:

    In:

    while($row = mysqli_fetch_array($result))
                  {
    

    $row = mysqli_fetch_array($result) does return a truthy value, but there is no code changing the query, so the server gets stuck in an infinite loop.

    Next, in:

    $result = mysqli_query($con,"SELECT * FROM admin where  Username='$username'"); 
    

    $username does not seem to be assigned. Im assuming it is assigned before the view is sent to the client?

    Try fixing these and see if it works as you intend it to.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题