dongliufa6380 2014-06-03 21:36
浏览 63
已采纳

php显示来自db的数据[关闭]

I'm trying to show data from my first row of db in a html page.. this is: index.html I don't understand where is wrong..

<div class="container">

  <h3>Menu del giorno <?php $currentDate = date("d-m-Y"); echo $currentDate;?></h3><br/>

<?php
$con=mysqli_connect("localhost","root","root","mydb");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM menu");


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

  echo "<p style="text-align: center;"><strong>Cucina:</strong></p><br/><br/>";
  echo "<p>Primi</p><br/>";
  echo "<p>" . $row['piatto1'] . "</p><br/>";
  echo "<p>" . $row['piatto2'] . "</p><br/><br/>";
  echo "<p>Secondo</p><br/>";
  echo "<p>" . $row['secondo'] . "</p><br/>";

  }
  mysqli_close($con);
  ?>

</div>
  • 写回答

2条回答 默认 最新

  • douda5227 2014-06-03 21:43
    关注

    First, your extension is wrong. It should, as other users have indicated, be titled index.php instead of index.html.

    Second, you might not be running this on a server. PHP is server side, meaning the code is executed before the user gets it, which is what makes it secure. The downside is that, unlike client-side things like javascript that operate/execute in the browser itself, for PHP you will need an actual server.

    If you aren't already uploading (with an FTP for example) to a server that supports PHP, you will have to make one yourself. An example for mac: MAMP.

    That will also support your SQL DB. Hope this helped!

    EDIT: Oh, I see a new error. When you have a quotation mark within a quotation mark, you need an escape sequence (" \" hello\" "). Otherwise PHP will think the second " is ending the first, instead of actually being in the string. So you should have, for example:

    echo "<p style=\"text-align: center;\"><strong>Cucina:</strong></p><br/><br/>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿