在CMS中插入表单 - <option>包含页面

时间:2015-06-18 01:50:39

标签: php mysql forms content-management-system

我整天都处于困境......我为CMS制作了表格和所需的一切,但真的不知道如何在不同的页面上添加或编辑数据...我有10页 - 10个文件。 php内容,并在页面上设置了一个锥形部分,我需要用我的表格注入数据.... 我只有一个解决方案,我尝试过。它是为所有页面创建data_table,为10页创建10form,然后在代码中更改表名。但是在网站上有太多的工作和太多的空间,我需要一个表来存储所有数据...如果有任何设置方法,请告诉我或给我建议。 PS。我在谷歌周围寻找例子,但我不明白,我无处可见这样的问题。 下面是我用于页面和表单的代码

  

添加表单的代码

    <?php
@session_start();
if(!isset($_SESSION['user_name'])) {

    header("location: login.php");
}
else {
?>

<html>
<head>
    <title>Insert new post</title>
</head>
<body>
<form method="post" action="dodavanje_artikla1.php" enctype="multipart/form-data">

    <table align="center" border="10" width="800">
        <tr>
            <td align="center" colspan="5" bgcolor="#5f9ea0"><h1>Here insert new article</h1></td>
        </tr>

        <tr>
            <td align="right">Insert title:</td>
            <td><input type="text" name="naziv" size="40"></td>
            <td><select>
                <option value="page1.php">p1</option>
                <option value="page2.php">p2</option>
                <option value="page3.php">p3</option>
                <option value="page4.php">p4</option>
                <option value="page5.php">p5</option>
                <option value="page6.php">p6</option>
                <option value="page7.php">p7</option>
                <option value="page8.php">p8</option>
                <option value="page9.php">p9</option>
                <option value="page10.php">p10</option>
            </select></td>
        </tr>

        <tr>
            <td align="right">Insert image:</td>
            <td><input type="file" name="image"></td>
        </tr>

        <tr>
            <td align="right">Insert content:</td>
            <td><textarea name="tekst" cols="40" rows="20"></textarea></td>
        </tr>

        <tr>
            <td align="center" colspan="5"><input type="submit" name="submit" value="Publish">
                <input type="reset" name="reset" value="Reset"></td>
        </tr>
    </table>
</form>

<?php
include "../editori/tinymce.php";
?>
</body>
</html>
<?php
include("include/connection.php");

if(isset($_POST['submit']))
{
    $title = $_POST['title'];
    $text = $_POST['content'];
    $image_name = $_FILES['image']['name'];
    $image_type = $_FILES['image']['type'];
    $image_size = $_FILES['image']['size'];
    $image_tmp = $_FILES['image']['tmp_name'];



    if($title=='' or $text=='')
    {
        echo "<script>alert('One or more field is blank')</script>";
        exit();
    }
    if($image_type=="image/jpeg" or $image_type=="image/png" or $image_type=="image/gif")
    {
        if($image_size<=50000)
        {
            move_uploaded_file($image_tmp,"images/$image_name");
        }
        else
        {
            echo "<script>alert('Image is too large, upload is limited till 50kb')</script>";
        }
    }
    else
    {
        echo"<script>alert('Type of image is invalid')</script>";
    }
    $query = "insert into artikli1 (title,image,content) values ('$title','$image_name','$text')";
    if(mysql_query($query))
    {
        echo "<script>window.open('index.php?published=Article is published','_self')</script>";
    }
}
?>
  

我需要放置的页面的代码

<div class="post_body">
                    <?php
                    include("include/connection.php");

                    $query = "select * from artikli1";
                    $run = mysql_query($query);
                    while ($row=mysql_fetch_array($run))
                    {
                        $artikli_ID = $row['artikli_ID'];
                        $title= $row['title'];
                        $image = $row['image'];
                        $text = $row['content'];

                        ?>
                    <dt><h5><a href="page.php?id=<?php echo $artikli_ID; ?>"><?php echo $title; ?></a></h5></dt>
                     <dt><br /><img src="images/<?php echo $image; ?>" width="100" height="100" /> </dt>
                    <dd><ul><?php echo $text; ?></ul></dd>
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="solidline"></div>
                        </div>
                    </div>
                    <?php } ?>

1 个答案:

答案 0 :(得分:0)

  

[已解决]问题

在数据库中,我添加了新的行type_article,设置了varchar,默认为NULL

然后改变了这部分代码

<td><select name:"lista">
            <option value="page1.php">page1</option>
            <option value="page2.php">page2</option>
            <option value="page3.php">page3</option>
            <option value="page4.php">page4</option>
            <option value="page5.php">page5</option>
            <option value="page6.php">page6</option>
            <option value="page7.php">page7</option>
            <option value="page8.php">page8</option>
            <option value="page9.php">page9</option>
            <option value="page10.php">page10</option>
        </select></td>

然后在代码$ type_articlepart

中添加
$title = $_POST['title'];
$text = $_POST['content'];
$image_name = $_FILES['image']['name'];
$image_type = $_FILES['image']['type'];
$image_size = $_FILES['image']['size'];
$image_tmp = $_FILES['image']['tmp_name'];
$type_article= $_POST['lista']
  

然后改变了下一个代码

$query = "insert into artikli1 (title,image,content,type_article) values ('$title','$image_name','$text','$type_article')";
  

在下一个代码中,我已更改

$query = "select * from artikli where type_article='page1'";
                    $run = mysql_query($query);
                    while ($row=mysql_fetch_array($run))
                    {
                        $artikli_ID = $row['artikli_ID'];
                        $title= $row['title'];
                        $image = $row['image'];
                        $text = $row['content'];

                        ?>

并在我想要更新文章的每个页面上包含此代码。

这就是......