我創建了一個表格,我嘗試將數據上傳到MySQL databasem,但提交表單後我收到以下錯誤..形式張貼到數據庫
注意:未定義指數:月C:\ xampp \ htdocs \ auto \ insert_ac.php第14行
注意:未定義索引:listner_name在C:\ xampp \ htdocs \ auto \ insert_ac.php上,第15行
注意:未定義索引:rj_name in C: \ xampp \ htdocs \ auto \ insert_ac.php on line 16
注意:未定義索引:第17行C:\ xampp \ htdocs \ auto \ insert_ac.php中的通道
N otice:未定義指數:今年在C:\ XAMPP \ htdocs中\在線自動\ insert_ac.php 18
注意:未定義指數:國家在C:\ XAMPP \ htdocs中\在線自動\ insert_ac.php 19
當我檢查插入到我的數據庫中的空白行條目
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username`
$password=""; // Mysql password
$db_name="auto"; // Database name
$tbl_name="song_request"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$month=mysql_real_escape_string($_POST['month']);
$listner_name=mysql_real_escape_string($_POST['listner_name']);
$rj_name=mysql_real_escape_string($_POST['rj_name']);
$channel=mysql_real_escape_string($_POST['channel']);
$year=mysql_real_escape_string($_POST['year']);
$country=mysql_real_escape_string($_POST['country']);
// Insert data into mysql
$sql="INSERT INTO song_request (month, listner_name, rj_name, channel, year, country)VALUES('$month', '$listner_name', '$rj_name', '$channel', '$year', '$country')";
$result=mysql_query($sql) or die ('error Updating database');
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='index.html'>Back to main page</a>";
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>
我的HTML表單代碼是
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Radio Mantra Song Request</title>
<link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css">
<link href="css/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.5.2.min.js">
</script>
<script type="text/javascript" src="js/jquery.autocomplete.pack.js">
</script>
<script type="text/javascript" src="js/script.js">
</script>
</head>
<body>
<div class="container">
<form name="form" method="post" action="insert_ac.php">
<p><label>Location:</label> <input id="month" type="text" autocomplete="off"></p>
<p><label>Listner Name:</label> <input id="listner_name" type="text" autocomplete=
"off"></p>
<p><label>RJ Name:</label> <input id="rj_name" type="text" autocomplete="off"></p>
<p><label>Channel:</label> <input id="channel" type="text" autocomplete="off"></p>
<p><label>Show Name:</label> <input id="year" type="text" autocomplete="off"></p>
<p><label>Song:</label> <input id="country" type="text" autocomplete="off"></p>
<h2>Radio Mantra</h2>
<table>
<tr>
<td align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
由於它的作品.. :)另外一件事..我如何限制空白條目到數據庫。 – 2011-12-22 12:29:52