繁体   English   中英

为什么我的表单被回显“ 0”代替?

[英]Why does my form get replaced with echo “0”?

我的页面上出现无法识别的错误,当我在线查看该网站时,它会将我的所有网站内容替换为值“ 0”。 为什么看不到表单,它与SQL Server正常通信?

PS:登录正常,并创建了会话,因此connect.php正常运行。

这是members.php的代码:

<?php 
// starting session
session_start();

// check if user is logged in
if (!isset($_SESSION['username']))
{
    header('Location: http://wwww.gjertgjersund.com/');
    exit();
}
else
{
    // database connection
    require ('connect.php');

    //post record count
    $post_count = mysql_query("SELECT * FROM posts");
    $post_count_result = mysql_num_rows($post_count);

    //comment count
    $comment_count = mysql_query("SELECT * FROM comments");
    $comment_count_result = mysql_num_rows($comment_count);

    if(isset($_POST['submit']))
    {
        $newcategory = $_POST['newcategory'];
        if(!empty($newcategory))
        {
            $query = mysql_query("INSERT * INTO categories (category) VALUES ('$newcategory')";
            if($query)
        {
            echo 'New category added';
        }
        }
        else
        {
            echo 'Error';
        }
    }
    else
    {
        echo 'Missing newcategory';
    }
}
?>

<!DOCTYPE HTML>
<html>
<head>
<title> Folder </title>
<body>

<div class="wrap">
    <div id="menu">
        <ul>
            <li><a href='#'>Home</a></li>
            <li><a href='#'>Create New Post</a></li>
            <li><a href='#'>Delete Post</a></li>
            <li><a href='logout.php'>Log Out</a></li>
            <li><a href='#'>Blog Home Page</a></li>
        </ul>
    </div>
    <div id="maincontent">
        <table>
            <tr>
                <td>Total Blog Post</td>
                <td><?php echo $post_count_result ?></td>
            </tr>
            <tr>
                <td>Total Comments</td>
                <td><?php echo $comment_count_result ?></td>
            </tr>
        </table>
        <div id="categoryform">
            <form action="members.php" method="post">
                <label for="category">Add New Category</label>
                <input type="text" name="newcategory"/>
                <input type="submit" name="submit" value="Create"/>
            </form>
        </div>
    </div>
</div>

</body>
</html>
$query = mysql_query("INSERT * INTO categories (category) VALUES ('$newcategory')";

应该

$query = mysql_query("INSERT INTO categories (category) VALUES ('$newcategory')";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM