2014-09-23 95 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