php为什么我这个代码显示不出来提交的内容呢?
我想提交后就显示出来提交的内容大家帮我看看最后一段代码哪里不对?<!DOCTYPEhtml><html><head><styletype="text/css"></sty...
我想提交后就显示出来提交的内容 大家帮我看看最后一段代码哪里不对?
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<form action="tiebacharu.php" method="post">
标题:<input type="text" name="title">
内容:<input type="text" name="content">
<input type="submit" >
</form>
</body>
</html>
-----------------------------
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("t1", $con);
$sql="INSERT INTO tieba(title,content)
VALUES('$_POST[title]','$_POST[content]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else{
echo "<script>alert('发布成功');location.href='xianshi.php'</script>";
}
mysql_close($con)
?>
--------------------------------------------------------
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
echo "连接数据库失败";
exit;
}
$sql='use t1';
mysql_query($sql,$con);
$title=isset($_GET['title'])?$_GET['title']:0;
$sql='select*from tieba where title='.$title;
if($rs=mysql_query($sql,$con)){
echo "$sql";
}else{
echo "失败";
}
?> 展开
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<form action="tiebacharu.php" method="post">
标题:<input type="text" name="title">
内容:<input type="text" name="content">
<input type="submit" >
</form>
</body>
</html>
-----------------------------
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("t1", $con);
$sql="INSERT INTO tieba(title,content)
VALUES('$_POST[title]','$_POST[content]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else{
echo "<script>alert('发布成功');location.href='xianshi.php'</script>";
}
mysql_close($con)
?>
--------------------------------------------------------
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
echo "连接数据库失败";
exit;
}
$sql='use t1';
mysql_query($sql,$con);
$title=isset($_GET['title'])?$_GET['title']:0;
$sql='select*from tieba where title='.$title;
if($rs=mysql_query($sql,$con)){
echo "$sql";
}else{
echo "失败";
}
?> 展开
1个回答
展开全部
$con = mysql_connect("localhost","root","");
if (!$con)
{
echo "连接数据库失败";
exit;
}
$sql='use t1';
mysql_query($sql,$con);
$where = ' ';
if(isset($_GET['title'])){
$where = ' title='.$title;
}
$sql='select*from tieba where ' .$where;
if($rs=mysql_query($sql,$con)){
while ($row = mysql_fetch_assoc($rs)) {
var_dump($row);
}
}else{
echo "失败";
}
最后一个改这个看看
更多追问追答
追问
不行 还是和原来一样
追答
你数据库里面有数据?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询