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 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?