0

我正在创建一个登录 + 新闻提要网站。我已经设置了所有需要的数据库。

这是所有网站的代码:

索引.php:

<?php

session_start();

 mysql_pconnect("MyServer","Username","Password");
  mysql_select_db("Database_Name");

  $page = $_GET['page'];

   ?>


   <html>
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>InstaWord</title>
    <link href="style.css" type="text/css" rel="stylesheet">
   </head>

    <body>
   <center>
   <table>
   <tr>
    <td id="body">

    <h1>News Feed <a href="?page=Home">Home</a></h1>




     <?php

    if ( !$page ) {

        $page = "Home";

    }

    include("$pages.php");

?>


      </td>
      <td id="nav">

      <?php

      if ( !$_SESSION['uid'] ) {

   ?> <a href="?page=Login">Login</a>

        <?php

     } else {

          ?>

          <a href="?page=Admin">Profile</a> | <a href="?page=Logout">Logout</a>

        <?php

   }

   ?>


   </td>
  </tr>
    </table>
  </center>
 </body>
 </html>

style.css 看起来像这样:

body {

background: #cfcfcf;
font-size: 12px;
line-height: 18px;
font-family: Trebuchet MS;
 }

  td {

font-size: 12px;
line-height: 18px;
font-family: Trebuchet MS;

   }


    #body {

background: #FFF;
border: 1px solid #000;
width: 600px;
padding: 10px;


    }

    #nav {

background: #FFF;
border: 1px solid #000;
padding: 10px;
width: 125px;
}

Home.php 看起来像这样:

<?php

$sql = mysql_query("SELECT * FROM `news1`") or die(mysql_error());

if ( mysql_num_rows($sql) == 0 ) {

   echo "There are no posts.";

} else {

   $sql = mysql_query("SELECT * FROM `news1` ORDER BY `time` DESC") or    die(mysql_error());

    while ( $row = mysql_fetch_assoc($sql) ) {

       echo "<hr>";

       echo "<h3>";

       echo $row['news_title'];

       echo "</h3>";

       echo $row['news_body'];



      }

      }

    ?>

Login.php 看起来像这样:

   <?php

   if ( !$_SESSION['uid'] ) {
   if ( !$_POST['submit'] ) {
   ?>  

   <form action="?page/Login"  method="post">
   <table>
   <tr>
   <td>Username</td>
   <td><input type="text" name="username"></td>
   </tr>
   <tr>
   <td>Password</td>
   <td><input type="password" name="password"></td>
   </tr>
   <td colspan="2">
   <input type="submit" value="Login" name="submut">
   </td>
   </tr>
   </table>
   </form> 

   <?php       
   } else {

       $username = $_POST['username'];
       $password = md5($_POST['password']);

       $errors = array();

       if ( !$username ) {

           $errors[1] = "Please enter a username.";

        }

        if ( !$password ) {

            $errors[2] = "Please enter a password";

        }


       $sql = "SELECT * FROM `users3` WHERE `name`='$username'";

       $res = mysql_query($sql) or die(mysql_error());

       $exists = mysql_num_rows($res);

       if ( $exists == 0 ) {

           $errors[3] = "The username does not exist!";

       } else {


            $sql = "SELECT * FROM `users3` WHERE `name`='$username' AND  `password`='$password'";

            $res = mysql_query($sql) or die(mysql_error());

            $exists = mysql_num_rows($res);

            if ( $exists == 0 ) {

                $errors[4] = "The username and password do not match.";

            }

     }


     if ( count($errors) > 0 ) {

         echo "<ul>";

         foreach ( $errors as $error ) {
             echo "<li>";
             echo $error;
             echo "</li>";
         }

         echo "</ul>

     } else {

          $sql = "SELECT * FROM `users3` WHERE `name`='$username' AND `password`='$password'";

          $res = mysql_query($sql) or die(mysql_error());

          $res = mysql_fetch_assoc($res);

          $_SESSION['uid'] = $res['user_id'];

          echo "You have successfully logged in! <a href=\"?  page=Home\">Home</a><br><br>";





     }


       }  else {

   echo "You are already logged in!";

   include("?pages/Home.php");

        }

       }
       }

       ?>

Logout.php 看起来像这样:

<?php

$_SESSION['uid'] = "";

?>
You have logged out!  

Admin.php 看起来像这样:

<?php

$action = $_GET['action'];

if ( !$action ) {
?>

<a href="?page=Admin&action=Post">Post News</a><br>
<a href="?page=Admin&action=Edit">Edit/Delete News</a><br>

<?php   
} else {

    if ( $action == "Post" ) {

    if ( !$_POST['submit'] ) {



    ?>

    <form action="?page=Admin&action=Post" method="post">
    <table>
      <tr>
        <td>News Title</td>
        <td><input type="text" name="news_title"></td>
        </tr>
        <tr>
        <td>News Body</td>
        <td><textarea name="news_body" cols="8" rows="4"></textarea></td>
        </tr>
        <tr>
        <td colspan="2">
        <input type="submit" name="submit" value="Post News">
        </td>
        </tr>
        </table>
        </form>


    <?php  

    } else {

        $user_id = $_SESSION['uid'];
        $news_title = $_POST['news_title'];
        $news_body = $_POST['news_body'];
        $time = time();

        $errors = array();

        if ( !$user_id ) {

            $errors[1] = "You are not logged in.";

        }

        if ( !$news_title ) {

            $errors[2] = "Please enter a title of the news.";

        }

        if ( !$news_body ) {

            $errors[3] = "Please enter a news body.";

        }

        if ( count($errors) > 0 ) {

            echo "<ul>";
            foreach ( $errors as $error ) {

                echo "<li>";
                echo $error;
                echo "</li>";

            }

            echo "</ul>";

        } else {

           $sql = mysql_query("INSERT INTO `news1` (`news_id`, `news_title`, `news_body`, `user_id`, `time`) 
           VALUES ('$news_title', '$news_body', '$user_id', '$time');';") or die(mysql_error());

           echo "You have posted the news successfully!";

        }


    }

    } elseif ( $action == "Edit" ) {

        if ( !$_GET['id'] ) {



             $sql = mysql_query("SELECT * FROM `news1`") or die(mysql_error());

             while ( $row = mysql_fetch_assoc($sql) ) {

             echo $row['news_title'] . " | <a href=\"?page=Admin&action=Edit&id=" . $row['news_id'] . "&type=Delete\">Delete</a><br>";

        }

        } else {

            $type = $_GET['type'];

            $id = $_GET['id'];

            if ( $type == "Delete" ) {

                $sql = mysql_query("DELETE FROM `news1` WHERE `news_id`='$id'") or die(mysql_error());
                echo "You successfully deleted the news entry.";

            }

        }

    }

}

    ?>

但请尝试继续http://www.youngcreativity.com

您可以在第一页看到错误:错误

在我的服务器上,我导入了这些文件:

服务器

请帮我解决这个问题。我已经卡在它上面很久了...

4

2 回答 2

0

问题在第 83 行

            echo "</ul>


             echo "</ul>"; 
于 2012-05-19T12:15:26.093 回答
0

在 index.php 第 39 行是:

包括(“$pages.php”);

应该是:

包括(“页面/$page.php”);

这将解决问题。

于 2012-05-19T12:03:00.503 回答