我就一菜鸟,纯自学的,所以就写了新闻的浏览,添加新闻两三个界面,还挺艰难- -。
麻烦求大家帮忙看看。
问题:
1、不是很懂MySQL,不会在数据库里添加内容,只会建数据库表单字段什么的,不知道是不是因为这个原因打开应该显示新闻列表的网页里面是空白的,什么内容都没有。
2、打开添加新闻的界面,把什么填好后提交,就提示我下载我写的那个php的脚本,然后就什么反应都没有了- -。可能问题有点白痴,但是还是劳烦大家了,想学这个又找不到可以问的人。麻烦大家帮我看了告诉我问题在哪里应该怎么改才可以呢。由于是菜鸟,没多少分,但我把有的分都拿出来了,只想弄清楚这个问题。谢谢,真心谢谢。
//connect.php<?php //连接到mysql
$conn = mysql_connect('localhost','root')or die(mysql_error()."不能连接到数据库!"); //连接数据库;
$db = mysql_select_db('news',$conn);
$page_size = 50; 
?>//list.php 显示新闻列表<html>
<head>
<title>新闻发布</title>
<body>
   <table border="0" width="500" height="20">
      <tr>
          <td align="center" width="300"><table border="0" width="500" height="20">
      <tr>
          <td align="center" width="300">标题</td>
          <td align="center" width="100">作者</td>
          <td align="center" width="100">时间</td>
      </tr>
   </table>
           
<?php
   include "conn.php"; 
   $title=$_POST['title'];
   $author=$_POST['author'];
   $datetime=$_POST['datetime'];
  
@ $db=new MySQLi('localhost','root',' ','news');if(MySQLi-connect-errno()){
echo 'Error:Could not connect to database.Please try again later.';
exit;
}$query="select title,author,datetime from news";
$result=$db->query($query);for($i=0;$i<15;$i++){
$row=$result->fetch_assoc();
echo "<p>";
echo htmlspecialchars(stirpslashes($row['title']));
echo stirpslashes($row['author']);
echo stirpslashes($row['datetime']);
echo "<br/>";
echo "</p>";
}$result->free();
$db->close();   
?></body>
</html>3、news_add.html添加新闻内容
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新闻录入</title>
</head><body alink="#FF0000">
<br>
<h1 align="center">新闻录入界面</h1>
<form action="news_add.php" method="post">
<table border="0">
<tr>
    <td>用户名</td>
    <td><input type="text" name="name" maxlength="12" size="12"></td>
    <td>密码</td>
    <td><input type="password" name="adminpsd" maxlength="16" size="16"></td>
</tr><br><tr>
    <td>标题</td>
    <td><input type="text" name="title" maxlength="60" size="30"></td>
</tr>
<tr>
    <td>作者</td>
    <td><input type="text" name="author" maxlength="30" size="30"></td>
</tr>
<tr>
    <td>内容</td>
    <td width="37">
    <textarea rows="12" name="content" cols="51"></textarea></td>
    <td width="34%"></td>
</tr><tr>
    <td colspan="2"><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
</body>
</html>4、news_add.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新闻录入</title>
</head><body>
<h1>新闻录入界面</h1>
<?php
  include "conn.php";
  $adminpsd=$_POST['adminpsd'];
  $name=$_POST['name'];
  $title=$_POST['title'];
  $author=$_POST['author'];
  $content=$_POST['content'];
  
  if($adminpsd||$name||$title||$author||$content){
  echo "You have not entered all the required details.<br/>";
  exit;
  }
  
  if(!get_magic_quotes_gpc()){
  $name=addslashes($name);
  $adminpsd=addslashes($adminpsd);
  $title=addslashes($title);
  $author=addslashes($author);
  $content=addslashes($content);
  }
  
@ $db_news=new MySQLi('localhost','root',' ','news');
@ $db_admin=new MySQLi('localhost','root',' ','admin');if(mysqli_connect_errno()){
echo"Error: Could not connect to database.Please try again later.";
exit;
}

$query_admin="select * from admin ";
$result_admin=$db_admin->query($query_admin);
$rows=$result_admin->fetch_assoc();if($adminpsd!=$rows['password']){
echo "管理密码错误<br/>";
exit;
}

$query_news="insert into news values('".title."','".author."','".content."')";
$result_news=$db_news->query($query_news);if($result_news){
echo $db_news->affect_rows."row(s) insert into database.";}
else{
echo "An error has occured.The item was not added.";}

$db_admin->close();
$db_news->close();
?>
</body>
</html>5、post.html 准备显示新闻的详细内容
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新闻浏览</title>
</head>
<body>
<center>
 <form action="List.php" method="post">
 <IFRAME  height=220 width=320  marginHeight=0 marginWidth=0 topmargin="0" leftmargin="0" scrolling=no frameBorder=0 background="bg.png"  ></IFRAME> 
 </form>
</center>
</body>
</html>

解决方案 »

  1.   

    就提示我下载我写的那个php的脚本,然后就什么反应都没有了 
    => 这个是环境没有搭配好 新手不太懂的话建议装个集成环境 如 wamp之类的 搜php集成环境就有了
    代码太长就没细看了 如果是学习的话建议一步步来
      

  2.   

    hoho 竟然是初学就慢慢进步吧,一个一个问题来解决,一个问题一个问题来学习。首先学会打开PHP的出错提示,这样你就知道基本上错误是什么个原因.
      

  3.   

    页面太多,代码太多,一般情况下都不看的,
    处错误了开启出错提示,加上echo等输出语句就能找到错误所在,执行数据库出错的时候多把sql语句打印出来放到mysql客户端执行看看有错没
      

  4.   

    第一步,学习调试
    1. 如何打开php错误显示