我想把数据从数据库中以表格形式输出,但现在就是输出不了从数据库传来的数据。不知道哪错了,求大神指导
<!DOCTYPEHTML><html><body><?php//链接数据库$conn=mysql_connect("localhost","root","12531")...
<!DOCTYPE HTML>
<html>
<body>
<?php
// 链接数据库
$conn=mysql_connect("localhost","root","12531");
if(!$conn)
{
die('Could not connet:'.mysql_error());
}
$dlkey=$_POST['DLkey'];
$project=$_POST['Project_Name'];
$version=$_POST['Version'];
$releasedate=$_POST['Release_Date'];
$ostype=$_POST['OS_Type'];
$owner=$_POST['Owner'];
$leader=$_POST['Leader'];
$ftp=$_POST['FTP'];
$driver=$_POST['Driver'];
//已传过来
//创建表
mysql_select_db("my_db",$conn);
$sql1="create table DriverList
(
DLkey int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(DLkey),
Project_Name varchar(30),
Version varchar(30),
Release_Date varchar(30),
OS_Type varchar(30),
Owner varchar(30),
Leader varchar(30),
FTP varchar(300),
Driver varchar(30)
)";
mysql_query($sql1,$conn);
mysql_query("INSERT INTO DriverList
(DLkey,Project_Name,Version,Release_Date,OS_Type,Owner,Le
ader,FTP,Driver) VALUES
('{$dlkey}','{$project}','{$version}','{$releasedate}','{
$ostype}','{$owner}','{$leader}','{$ftp}','{$driver}')");
$result = mysql_query("SELECT * FROM DriverList order by
DLkey");
function show($result)
{
echo "<table border='1'>
<tr>
<th>DLkey</th>
<th>Project_Name</th>
<th>Version</th>
<th>Release_Date</th>
<th>OS_Type</th>
<th>Owner</th>
<th>Leader</th>
<th>FTP</th>
<th>Driver</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['DLkey'] . "</td>";
echo "<td>" . $row['Project_Name'] . "</td>";
echo "<td>" . $row['Version'] . "</td>";
echo "<td>" . $row['Release_Date'] . "</td>";
echo "<td>" . $row['OS_Type'] . "</td>";
echo "<td>" . $row['Owner'] . "</td>";
echo "<td>" . $row['Leader'] . "</td>";
echo "<td>" . $row['FTP'] . "</td>";
echo "<td>" . $row['Driver'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
show($result);
mysql_close($conn);
?>
</body>
</html> 展开
<html>
<body>
<?php
// 链接数据库
$conn=mysql_connect("localhost","root","12531");
if(!$conn)
{
die('Could not connet:'.mysql_error());
}
$dlkey=$_POST['DLkey'];
$project=$_POST['Project_Name'];
$version=$_POST['Version'];
$releasedate=$_POST['Release_Date'];
$ostype=$_POST['OS_Type'];
$owner=$_POST['Owner'];
$leader=$_POST['Leader'];
$ftp=$_POST['FTP'];
$driver=$_POST['Driver'];
//已传过来
//创建表
mysql_select_db("my_db",$conn);
$sql1="create table DriverList
(
DLkey int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(DLkey),
Project_Name varchar(30),
Version varchar(30),
Release_Date varchar(30),
OS_Type varchar(30),
Owner varchar(30),
Leader varchar(30),
FTP varchar(300),
Driver varchar(30)
)";
mysql_query($sql1,$conn);
mysql_query("INSERT INTO DriverList
(DLkey,Project_Name,Version,Release_Date,OS_Type,Owner,Le
ader,FTP,Driver) VALUES
('{$dlkey}','{$project}','{$version}','{$releasedate}','{
$ostype}','{$owner}','{$leader}','{$ftp}','{$driver}')");
$result = mysql_query("SELECT * FROM DriverList order by
DLkey");
function show($result)
{
echo "<table border='1'>
<tr>
<th>DLkey</th>
<th>Project_Name</th>
<th>Version</th>
<th>Release_Date</th>
<th>OS_Type</th>
<th>Owner</th>
<th>Leader</th>
<th>FTP</th>
<th>Driver</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['DLkey'] . "</td>";
echo "<td>" . $row['Project_Name'] . "</td>";
echo "<td>" . $row['Version'] . "</td>";
echo "<td>" . $row['Release_Date'] . "</td>";
echo "<td>" . $row['OS_Type'] . "</td>";
echo "<td>" . $row['Owner'] . "</td>";
echo "<td>" . $row['Leader'] . "</td>";
echo "<td>" . $row['FTP'] . "</td>";
echo "<td>" . $row['Driver'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
show($result);
mysql_close($conn);
?>
</body>
</html> 展开
1个回答
展开全部
全部写成一个html文件,写文件的形式。
echo “<html>”
echo “<head>”
echo “</head>”
echo “<baody>”
echo “<table>”
echo $your_data_here
echo “</table>”
echo “</body>”
echo “</html>”
echo “<html>”
echo “<head>”
echo “</head>”
echo “<baody>”
echo “<table>”
echo $your_data_here
echo “</table>”
echo “</body>”
echo “</html>”
追问
这个估计是没有写入数据库,或者没有选出来。我就是想找出这个错误
追答
你可以做一个testing,一步步来。
a).你先check下table 是否create成功。
b).再次check insert动作之后查看数据库是否有data
c).最后check data是否能在正常获取。
d).还有一点就是show data的时候会不会连html代码一起show出来,这个你应该懂得
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询