我得到在我的網頁下面的5個錯誤:爲什麼我會得到「未定義的索引」?
Notice: Undefined index: town in C:\xampp\htdocs\dispatch1.php on line 51
Notice: Undefined index: location in C:\xampp\htdocs\dispatch1.php on line 52
Notice: Undefined index: incident_type in C:\xampp\htdocs\dispatch1.php on line 53
Notice: Undefined index: time_date in C:\xampp\htdocs\dispatch1.php on line 54
Notice: Undefined index: admin in C:\xampp\htdocs\dispatch1.php on line 55
這裏是我是從數據庫中獲取數據(它確實表明從數據庫精細的數據),我的輸出表的代碼:
<?php include("manage_post.php"); ?>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta http-equiv="refresh" content="2" >
</head>
<body>
<div align="center" class="CSSTableGenerator" height="100%">
<form action="dispatch1.php" method="get" id="dispatch">
<table width="968" height="248" border="1" align="center" cellpadding="10" cellspacing="0" rules="rows" id="incidents" style="color:#333333;border-collapse:collapse;text-align:left;">
<tr style="color:White;background-color:#5D7B9D;font-weight:bold;font-style:italic;">
<th scope="col">TOWN</th>
<th scope="col">LOCATION</th>
<th scope="col">INCIDENT TYPE</th>
<th scope="col">TIME/DATE</th>
<th scope="col">ADMIN</th>
</tr>
<tr style="color:#333333;background-color:#F7F6F3;font-weight:bold;">
<?php
$town = $_POST['town'];
$location = $_POST['location'];
$incident_type= $_POST['incident_type'];
$time_date= $_POST['time_date'];
$admin = $_POST['admin'];
$db = mysqli_connect('localhost','root','') or die("Database error");
mysqli_select_db($db, 'mydatabase');
$result= mysqli_query($db, "select * from cad");
while($row = mysqli_fetch_array($result))
{
echo "<td>" .$row['town'] ."</td>";
echo "<td>" .$row['location'] ."</td>";
echo "<td>" .$row['incident_type'] ."</td>";
echo "<td>" .$row['time_date'] ."</td>";
echo "<td>" .$row['admin'] ."</td>";
}
?>
</tr>
</table>
</form>
</body>
</html>
然後,這是我的「manage_post.php」頁面,並將數據從表單的數據庫:
<?php
if($_POST)
{
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydatabase", $con);
$town = $_POST['town'];
$location = $_POST['location'];
$incident_type = $_POST['incident_type'];
$time_date = $_POST['time_date'];
$admin = $_POST['admin'];
$town = mysql_real_escape_string($town);
$location = mysql_real_escape_string($location);
$incident_type = mysql_real_escape_string($incident_type);
$time_date = mysql_real_escape_string($time_date);
$admin = mysql_real_escape_string($admin);
$query = "
INSERT INTO `mydatabase`.`cad` (`town`, `location`, `incident_type`, `time_date`, `admin`) VALUES ('$town', '$location', '$incident_type', '$time_date', '$admin');";
mysql_query($query);
mysql_close($con);
}
?>
我試圖通過它和f找出它有什麼問題,但找不到它。如果您需要表單代碼,請告訴我。我的PHP代碼的另一個奇怪的問題是,表格不是垂直的,而是水平的,並且一直在屏幕上。 Here is a picture of it.然後我必須水平滾動才能查看所有內容。
您是否將變量聲明在文檔的頂部?例如¤var=「」; –
實際上在'cad'表中有'town'列嗎? – 0b10011
您的表很長,因爲您的