首先,我有index.php文件中的代碼包含如下無法建立與PHP數據庫連接
<form action="connection.php" method="post">
<table>
<thead><tr><td>Enter Item Details</td></tr></thead>
<tr>
<td>Item name :- </td>
<td><input type="text" maxlength="30" name="item_name"></td>
</tr>
<tr>
<td>Item Desc :- </td>
<td><input type="text" maxlength="150" name="item_desc"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Add Item">
</td></tr>
</table>
</form>
和我connection.php由代碼如下
$host="localhost";
$username="root";
$password="";
$db_name="eatery";
$tbl_name="test_item";
mysql_connect("$host", "$username", "$password") or die("Not able to connect to MySql");
echo "connected";
mysql_select_db("$db_name") or die ("Not able to connect to eatery database");
我已經安裝WAMP包運行Apache服務器和我的PHP代碼。現在點擊index.php的提交按鈕,而不是數據庫連接成功/失敗消息,它顯示了connection.php的內部代碼。所以我在這裏錯過了什麼?
它顯示了connection.php的確切內容? – lagbox
確保你不會忘記在** connection.php **腳本和'?>'末尾寫入'<?php'。否則,服務器將其視爲常規文本/ html。 – Wh1T3h4Ck5
我認爲標題需要調整。這不是數據庫問題。 – lagbox