duandan9680 2013-06-10 09:26
浏览 44
已采纳

为什么我的表单被echo“0”替换?

I got an error on my page that I can't identify, and when I view the site online it replaces all my site content with the value "0". How come I can't see the forms, and is it communicating with the SQL server properly?

PS: Login works and session is created, so the connect.php does work properly.

Here is the code for 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>
  • 写回答

1条回答 默认 最新

  • doudang9147 2013-06-19 05:39
    关注
    $query = mysql_query("INSERT * INTO categories (category) VALUES ('$newcategory')";
    

    should be

    $query = mysql_query("INSERT INTO categories (category) VALUES ('$newcategory')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据