有人可以查看我的代碼並讓我知道它有什麼問題嗎?連接Php,html和mysql
我遇到的問題是,當我輸入3個字段的文本並點擊提交時,它不會插入到我的數據庫(mysql,以phpmyadmin作爲gui)。沒有錯誤信息或任何東西;它只是不插入數據。我已經查看了一遍又一遍的代碼,我不能指出它有什麼不對。
//---------------------------This is my index.php------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Web Bar Title</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
<body>
<?php
if(isset($_POST['Submit']))
{
include 'connectdb.php';
include 'openconnection.php';
$first = $_POST['first'];
$second = $_POST['second'];
$third = $_POST['third'];
$query = "INSERT INTO details (first, last, third) VALUES('$first','$second','$third');";
mysql_query($query) or die('Error, insert query failed');
}
?>
<div id="page">
<tbody>
<form method="post">
<table>
<tr>
<td ><b>First</b></td>
<td><input name="first" type="text" id="first"></td>
<tr>
<tr>
<td ><b>Second</b></td>
<td><input name="second" type="text" id="second"></td>
<tr>
<td ><b>Company</b></td>
<td><input name="third" type="text" id="third" > </td>
</tr>
</table>
<input name="submit" type="submit" id="submit" value="Submit" />
</form>
</body>
</html>
</tbody>
</div>
//---------------------------------connectdb.php------------------------------------------
<?php
$dbhost = 'localhost';
$dbuser = 'sharkk';
$dbpass = 'pw';
$dbname = 'test';
?>
//---------------------------------openconnection.php-------------------------------------
<?php
$dbhost = 'localhost';
$dbuser = 'sharkk';
$dbpass = 'pw';
$dbname = 'test';
?>
<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname) or die ('No Selection of Database');
?>
編輯:它會更容易和更快的通過MSN/AIM /蒸汽/ Skype的溝通,如果任何人有任何這些!
它再次顯示頁面? – shevski 2011-04-18 07:35:37
寫上頁面'error_reporting(E_ALL); ini_set('display_errors','on');'並看到錯誤 – diEcho 2011-04-18 07:41:00
把'die($ query)'放在你建立查詢的區域下面並告訴我們會發生什麼 – JohnP 2011-04-18 07:51:15