2014-09-23 94 views
0

嗨,我试图在云9 执行以下代码:MySQL表云不显示HTML表格9

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <title>Test | Products</title> 
    </head> 

    <body> 
     <?php 
      $con=mysqli_connect(0.0.0.0,"ritikasahay","","trydb"); 

      if (mysqli_connect_errno()) { 
       echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
      } 

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

      echo "<table border='1'> 
      <tr> 
       <th>Name</th> 
       <th>Price</th> 
       <th>Image</th> 
      </tr>"; 

      while($row = mysqli_fetch_array($result)) { 
       echo "<tr>"; 
       echo "<td>" . $row['name'] . "</td>"; 
       echo "<td>" . $row['price'] . "</td>"; 
       echo "<td>" . $row['image'] . "</td>"; 
       echo "</tr>"; 
      } 

      echo "</table>"; 

      mysqli_close($con); 
      ?> 
    </body> 
</html> 

当我执行这个代码,我想起来了下面的PHP代码结果而不是表格内容:

Name Price Image "; while($row = mysqli_fetch_array($result)) { echo ""; echo "" . $row['name'] . ""; echo "" . $row['price'] . ""; echo "" . $row['image'] . ""; echo ""; } echo ""; mysqli_close($con); ?> 

有人可以告诉我,我错了吗?

+2

不该文件具有'.php'延伸? – 2014-09-23 07:28:54

回答

0

昌此命令:

$con=mysqli_connect(0.0.0.0,"ritikasahay","","trydb"); 

像这样:

$con=mysqli_connect("0.0.0.0","ritikasahay","","trydb"); 
+0

是的,在更改语法之后,我得到以下结果:无法连接到MySQL:拒绝用户'ritikasahay'@'localhost'的访问(使用密码:否) 名称\t价格\t图片 – ritika 2014-09-23 07:44:57

0

表显示一次,而不是多次

<!DOCTYPE html> 
<html lang="en"> 
    <head> 

     <title>Test | Products</title> 

    </head> 
    <body> 
     <?php 
$con=mysqli_connect("0.0.0.0","ritikasahay","","trydb"); 

if (mysqli_connect_errno()) { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

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

//create table 
$table = "<table border='1'> 
<tr> 
<th>Name</th> 
<th>Price</th> 
<th>Image</th> 
</tr>"; 

while($row = mysqli_fetch_array($result)) { 
    //bind rows 
    $table .= "<tr>"; 
    $table .= "<td>" . $row['name'] . "</td>"; 
    $table .= "<td>" . $row['price'] . "</td>"; 
    $table .= "<td>" . $row['image'] . "</td>"; 
    $table .= "</tr>"; 
} 

//close table 
$table .= "</table>"; 

//display table 
echo $table; 

mysqli_close($con); 
?> 
    </body> 
</html> 
+0

仍然无法正常工作,出现以下错误:无法连接到MySQL:访问拒绝用户'ritikasahay'@'localhost'(使用密码:否) – ritika 2014-09-23 07:51:46

+0

什么是您的密码。更新适当的mysql连接细节,然后这应该工作“$ con = mysqli_connect(”localhost“,”ritikasahay“,”“,”trydb“);”更新正确的用户名和密码 – Sundar 2014-09-23 07:55:02

+0

我很抱歉,我很新的PHP,所以我很积极天真。我的数据库没有密码,我也尝试了我的cloud9密码,但它不起作用 – ritika 2014-09-23 07:57:16