MySQLi添加/编辑不工作也不显示错误

时间:2013-08-31 17:12:11

标签: php mysqli

我是MySQLi的新手,我没有做任何部分MySQL和PHP但没有加载,我正在尝试正确学习,但MySQLI现在已经弃用了MySQL ..我的问题是,当我添加一些细节时,它重定向到我我想要的页面应该是什么时候添加细节,但实际上并没有将任何信息插入到数据库中,我试过看phpMyAdmin并且它无法正常工作..当我点击编辑文件时它给了我此错误:致命错误:允许的内存大小为67108864字节耗尽(尝试分配4294967296字节)....

这是文件:

    <?php
     include("includes/connecti.php");

      function renderForm($title = '', $poster ='', $date = '', $story = '', $error = '', $id = '')
    { ?>
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
            <html>
             <head>  
          <title>
              <?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?>
              </title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
              </head>
          <body>
        <h1><?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1>
         <?php if ($error != '') {
         echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error
                                            . "</div>";
                } ?>


            <form action="" method="post">
            <div>
            <?php if ($id != '') { ?>
           <input type="hidden" name="id" value="<?php echo $id; ?>" />
           <p>ID: <?php echo $id; ?></p>
          <?php } ?>
          <strong>Title: *</strong> <input type="text" name="title" value="<?php echo $title; ?>"/><br/>
        <strong>Poster: *</strong> <input type="text" name="poster" value="<?php echo $poster; ?>"/>
         <strong>Date: *</strong> <input type="text" name="date" value="<?php echo $date; ?>"/>
         <strong>Story: *</strong> <input type="text" name="story" value="<?php echo $story; ?>"/>
        <p>* required</p>
     <input type="submit" name="submit" value="Submit" />
       </div>
       </form>
       </body>
      </html>

    <?php }



    /*

       EDIT RECORD

    */
    if (isset($_GET['id']))
    {

   if (isset($_POST['submit']))
      {
                    if (is_numeric($_POST['id']))
                    {
                   $id = $_POST['id'];
                   $title = htmlentities($_POST['title'], ENT_QUOTES);
                 $poster = htmlentities($_POST['poster'], ENT_QUOTES);
               $date = htmlentities($_POST['date'], ENT_QUOTES);
                $story = htmlentities($_POST['story'], ENT_QUOTES);

            if ($title == '' || $poster == '' || $date == '' || $story == '')
               {
          $error = 'ERROR: Please fill in all required fields!';
           renderForm($title, $poster, $date, $story, $error, $id);
           }
                else
            {

         if ($stmt = $mysqli->prepare("UPDATE news SET title = ?, poster = ?, date = ?, story = ? WHERE id=?"))
                     {
               $stmt->bind_param("ssi", $title, $poster, $date, $story, $id);
              $stmt->execute();
               $stmt->close();
                      }
              else
                    {
              echo "ERROR: could not prepare SQL statement.";
                           }

                                    header("Location: view.php");
                            }
                    }

                    else
                    {
                            echo "Error!";
                    }
            }
        else
            {

                    if (is_numeric($_GET['id']) && $_GET['id'] > 0)
                    {

                            $id = $_GET['id'];


                            if($stmt = $mysqli->prepare("SELECT * FROM news WHERE id=?"))
                            {
                                    $stmt->bind_param("i", $id);
                                    $stmt->execute();

                                    $stmt->bind_result($id, $title, $poster, $date, $story);
                                    $stmt->fetch();

                                    renderForm($title, $poster, $date, $story, NULL, $id);

                                    $stmt->close();
                            }

                            else
                            {
                                    echo "Error: could not prepare SQL statement";
                            }
                    }

                    else
                    {
                            header("Location: view.php");
                    }
            }
    }



    /*

       NEW RECORD

    */
    // if the 'id' variable is not set in the URL, we must be creating a new record
    else
    {
            // if the form's submit button is clicked, we need to process the form
            if (isset($_POST['submit']))
            {
                    // get the form data
                          $title = htmlentities($_POST['title'], ENT_QUOTES);
                $poster = htmlentities($_POST['poster'], ENT_QUOTES);
                  $date = htmlentities($_POST['date'], ENT_QUOTES);
                     $story = htmlentities($_POST['story'], ENT_QUOTES);

                    if ($title == '' || $poster == '' || $date == '' || $story == '')
                    {

                            $error = 'ERROR: Please fill in all required fields!';
                            renderForm($title, $poster, $date, $story, $error);
                    }
                    else
                    {

                            if ($stmt = $mysqli->prepare("INSERT news (title, poster, date, story) VALUES (?, ?, ?, ?)"))
                            {
                                    $stmt->bind_param("ss", $title, $poster, $date, $story);
                                    $stmt->execute();
                                    $stmt->close();
                            }

                            else
                            {
                                    echo "ERROR: Could not prepare SQL statement.";
                            }

                            header("Location: view.php");
                    }

            }

            else
            {
                    renderForm();
            }
    }

    $mysqli->close();
        ?>

1 个答案:

答案 0 :(得分:0)

您的列之一是LONGBLOB还是LONGTEXT?

PHP尝试分配足够的内存来保存该列的最大大小(4,294,967,296字节)。请看这里(注意页面上的最后一篇文章):

http://bugs.php.net/bug.php?id=51386

如果是这种情况,请将列更改为MEDIUMTEXT或MEDIUMBLOB,如果可以使用它,则将其更小。