MySQLi添加/编辑不起作用,也不显示错误


MySQLi add/edit not working nor showing errors

我是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();
        ?>

您的某个列是LONGBLOB还是LONGTEXT?

PHP试图分配足够的内存来容纳该列的最大大小(4294967296字节)。请参阅此处(注意页面上的最后一篇文章):

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

如果是这种情况,请将列更改为MEDIUMTEXT或MEDIUMBLOB,或者更小的列(如果可以的话)。