大型PHP表单上传不起作用

时间:2018-04-09 14:14:07

标签: php mysql

我正在尝试为我正在处理的网站创建自定义博客系统,我创建了所有系统但是当我尝试将表单插入数据库时​​,脚本会执行,但数据不会保存到数据库。有些字段确实包含大量文本,使用TinyMCE进行格式化可能会出现问题吗?当我使用较少量的文本进行测试时,它可以正常工作。

PHP脚本:

$conn = connect();
$action = $_GET['a'];
$id = $_GET['id'];
switch($action) {
case 'delete':
    $sql = "DELETE FROM articles WHERE id='$id'";
    if(mysql_query($sql)) {
        echo "<script type='text/javascript'> alert('Article Deleted'); </script>";
        header("Location: manage.php");
    }   
break;

case 'add':
if(isset($_POST['submit'])) {
$slug = $_POST['slug'];
$datecreated = $_POST['datecreated'];
$datepublish = $_POST['datepublish'];
$author = $_POST['author'];
$status = $_POST['status'];
$title = $_POST['title'];
$miniexcerpt = $_POST['miniexcerpt'];
$teaser = $_POST['teaser'];
$body = $_POST['body'];
    $sql = "INSERT INTO articles (slug,datecreated,datepublish,author,status,title,miniexcerpt,teaser,body) values ('$slug','$datecreated','$datepublish','$author','$status','$title','$miniexcerpt','$teaser','$body')";
    if(mysql_query($sql)) {
        echo "<script type='text/javascript'> alert('Article Added'); </script>";
        header("Location: manage.php");
    }
}
break;

case 'edit':
if(isset($_POST['submit'])) {
$slug = $_POST['slug'];
$datecreated = $_POST['datecreated'];
$datepublish = $_POST['datepublish'];
$author = $_POST['author'];
$status = $_POST['status'];
$title = $_POST['title'];
$miniexcerpt = $_POST['miniexcerpt'];
$teaser = $_POST['teaser'];
$body = $_POST['body'];
    $sql = "UPDATE articles SET slug='$slug',datecreated='$datecreated',datepublish='$datepublish',author='$author',status='$status',title='$title',miniexcerpt='$miniexcerpt',teaser='$teaser',body='$body' WHERE id='$id'";
    if(mysql_query($sql)) {
        echo "<script type='text/javascript'> alert('Article Updated'); </script>";
        header("Location: manage.php");
    }
    }
break;  

}

$conn = connect();
$action = $_GET['a'];
$id = $_GET['id'];
switch($action) {
case 'publish':
    $sql = "UPDATE articles SET status='published' WHERE id='$id'";
    if(mysql_query($sql)) {
        echo "<script type='text/javascript'> alert('Article Published'); </script>";
        header("Location: manage.php");
    }   
break;
}

HTML表单:

<form id="form" name="form" action="articlefunctions.php?a=add" method="post">
            <div class="form-group row">
                <label for="title" class="col-sm-2 col-form-label">Article Title</label>
                <div class="col-sm-10">
                    <input name="title" type="text" id="title" class="form-control" placeholder="Article Title" />
                </div>
            </div>
            <div class="form-group row">
                <label for="slug" class="col-sm-2 col-form-label">Article URL (Slug)</label>
                <div class="col-sm-10">
                    <input name="slug" type="text" id="slug" class="form-control" placeholder="Article URL - Must NOT include spaces - use '-' instead" />
                </div>
            </div>
            <div class="form-group row">
                <label for="teaser" class="col-sm-2 col-form-label">Article Excerpt</label>
                <div class="col-sm-10">
                    <textarea name="teaser" id="teaser" placeholder="Article Excerpt" rows="4"></textarea>
                </div>
            </div>
            <div class="form-group row">
                <label for="miniexcerpt" class="col-sm-2 col-form-label">Homepage Excerpt</label>
                <div class="col-sm-10">
                    <textarea name="miniexcerpt" id="miniexcerpt" maxlength="180" placeholder="Snippet from excerpt to go on homepage" rows="4"></textarea>
                    <span id='remainingC' class="pull-right"></span>
                </div>
            </div>
            <div class="form-group row">
                <label for="body" class="col-sm-2 col-form-label">Article Content</label>
                <div class="col-sm-10">
                    <textarea name="body" id="body" rows="8"></textarea>
                </div>
            </div>
            <div class="form-group row">
                <label for="author" class="col-sm-2 col-form-label">Article Author</label>
                <div class="col-sm-10">
                    <input name="author" type="text" id="author"  readonly class="form-control" value="<?php echo $_SESSION['user_name'];?>" />
                </div>
            </div>
            <div class="form-group row">
                <label for="status" class="col-sm-2 col-form-label">Article Status</label>
                <div class="col-sm-10">
                    <select name="status" id="status" class="form-control" />
                        <option value="draft" selected>draft</option>
                        <option value="published">published</option>
                    </select>
                </div>
            </div>
            <input name="datecreated" type="hidden" id="datecreated" value="<?php echo date('Y-m-d'); ?>" class="form-control" />
            <div class="form-group row">
                <label for="datepublish" class="col-sm-2 col-form-label">Publish Date</label>
                <div class="col-sm-10">
                    <input name="datepublish" type="date" id="datepublish" class="form-control" />
                </div>
            </div>
            <div class="form-group row">
                <input type="submit" value="Save" id="submit" name="submit" class="btn btn-primary"/>
            </div>
        </form>

1 个答案:

答案 0 :(得分:0)

检查你的php.ini。某些参数会影响POST有效负载大小。

  

post_max_size整数       设置允许的后期数据的最大大小。此设置也会影响文件上载。要上传大文件,此值必须大于upload_max_filesize。一般来说,memory_limit应该大于post_max_size。使用整数时,该值以字节为单位。也可以使用本FAQ中描述的速记符号。如果发布数据的大小大于post_max_size,则$ _POST和$ _FILES超全局变量为空。这可以以各种方式跟踪,例如,通过将$ _GET变量传递给处理数据的脚本,即检查是否设置了$ _GET ['processed']。

source