Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
致命错误:第140行的/home/news-insert.php中允许的内存大小536870912字节已用完(尝试分配4294967296字节)_Php_Html_Mysqli - Fatal编程技术网

致命错误:第140行的/home/news-insert.php中允许的内存大小536870912字节已用完(尝试分配4294967296字节)

致命错误:第140行的/home/news-insert.php中允许的内存大小536870912字节已用完(尝试分配4294967296字节),php,html,mysqli,Php,Html,Mysqli,我在做一个项目,我在做一个页面,应该做更新和定期插入工作。我在其他地方找到了代码,并一直在修改它以用于我的项目。不管怎样,我修复了许多错误,但我在第140行一直出现内存泄漏 代码如下: <?php /* Allows the user to both create new records and edit existing records */ // connect to the database include("include

我在做一个项目,我在做一个页面,应该做更新和定期插入工作。我在其他地方找到了代码,并一直在修改它以用于我的项目。不管怎样,我修复了许多错误,但我在第140行一直出现内存泄漏

代码如下:

    <?php
     /*
     Allows the user to both create new records and edit existing records
     */

     // connect to the database
     include("includes/dbconnect.inc.php");

     // creates the new/edit record form
     // since this form is used multiple times in this file, I have made it a function that is easily reusable
     function renderForm($title = '', $summary ='', $entry = '', $error = '', $id = '')
     { ?>
     <?php 
     include("includes/header.inc.php");
     ?>
     <body>
     <table>
     <tr>
     <td>
     <img src="images/zombie_minions.png"/> <!--  Logo  -->
     </td>
     <td>
     <div id="nav"><ul>
     <li><a href="index.php">Home</a></li>
     <li><a href="news.php">News</a></li>
     <li><a href="about.php">About Us</a></li>
     <li><a href="signup.php">Sign Up</a></li>
     <li><a href="contact.php">Contact Us</a></li>
     <li><a  class="active"  href="news-insert.php">New/Update News Entry</a></li>
     <li><a href="/admin/">Admin Panel</a></li>
     <li><a href="/staff/">Staff Admin Panel</a></li>
     <li><a href="/client/">Client Panel</a></li>
     <li><a href="login.php">Login</a></li>
     <li><a href="logout.php">Log Out</a></li>
     </ul></div>
     </td>
     </tr>
     <tr>
     <?php
     include("includes/calendar.inc.php");
     ?>
     <td>
     <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">
       <h2><strong>Edit News Item:</strong></h2><br><br>
       <input type="hidden" name="id" value="<?php echo $id; ?>" />
       <p>ID: <?php echo $id; ?></p>
      <!-- Date:<br>
       <input type="text" name="date" value="<?php echo $date; ?>"/><br>  -->
       Post Title:<br>
       <input type="text" name="title" min="0" max="100" value="<?php echo $title; ?>" required /><br>
       Post Summary:<br>
       <input type="text" name="summary" min="0" max="100" value="<?php echo $summary; ?>" required /><br>
       Post Entry:<br>
       <textarea type="text" name="entry" rows="4" cols="50" min="0" max="650" value="<?php echo $entry; ?>" required /></textarea><br>

       <input type="submit" value="Submit" name="submit" />
     </form>

     <?php }



     /*

     EDIT RECORD

     */
     // if the 'id' variable is set in the URL, we know that we need to edit a record
     if (isset($_GET['id']))
    {
     // if the form's submit button is clicked, we need to process the form
     if (isset($_POST['submit']))
     {
     // make sure the 'id' in the URL is valid
     if (is_numeric($_POST['id']))
     {
     // get variables from the URL/form
     $id = $_POST['ID'];
     $title = htmlentities($_POST['title'], ENT_QUOTES);
     $summary = htmlentities($_POST['summary'], ENT_QUOTES);
     $entry = htmlentities($_POST['entry'], ENT_QUOTES);
     //$date=date('y.m.d h:i:s');

     // check that title and summary are both not empty
     if ($title == '' || $summary == '' || $entry == '')
     {
     // if they are empty, show an error message and display the form
     $error = 'ERROR: Please fill in all required fields!';
     renderForm($title, $summary, $entry, $error, $id);
     }
     else
     {
     // if everything is fine, update the record in the database
     if ($stmt = $conn->prepare("UPDATE news SET title = ?, summary = ?, entry - ?
     WHERE id=?"))
     {
     $stmt->bind_param("sssi", $title, $summary, $entry, $id);
     $stmt->execute();
     $stmt->close();
     }
     // show an error message if the query has an error
     else
     {
     echo "ERROR: could not prepare SQL statement.";
     }

     // redirect the user once the form is updated
     header("Location: news.php");
     }
     }
     // if the 'id' variable is not valid, show an error message
     else
     {
     echo "Error!";
     }
     }
     // if the form hasn't been submitted yet, get the info from the database and show the form
     else
     {
     // make sure the 'id' value is valid
     if (is_numeric($_GET['id']) && $_GET['id'] > 0)
     {
     // get 'id' from URL
     $id = $_GET['id'];

     // get the recod from the database
     if($stmt = $conn->prepare("SELECT ID, title, summary, entry FROM news WHERE ID=?"))
     {
     $stmt->bind_param("i", $id);
     $stmt->execute();

     $stmt->bind_result($id, $title, $summary, $entry);
     $stmt->fetch();

     // show the form
     renderForm($title, $summary, $entry, NULL, $id);

     $stmt->close();
     }
     // show an error if the query has an error
     else
     {
     echo "Error: could not prepare SQL statement";
     }
     }
     // if the 'id' value is not valid, redirect the user back to the news.php page
     else
     {
     header("Location: news.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);
     $summary = htmlentities($_POST['summary'], ENT_QUOTES);
     $entry = htmlentities($_POST['entry'], ENT_QUOTES);

     // check that title and summary are both not empty
     if ($title == '' || $summary == '' || $entry == '')
     {
     // if they are empty, show an error message and display the form
     $error = 'ERROR: Please fill in all required fields!';
     renderForm($title, $summary, $entry, $error);
     }
     else
     {
     // insert the new record into the database
     if ($stmt = $conn->prepare("INSERT news (title, summary, entry) VALUES (?, ?, ?)"))
     {
     $stmt->bind_param("sss", $title, $summary, $entry);
     $stmt->execute();
     $stmt->close();
     }
     // show an error if the query has an error
     else
     {
     echo "ERROR: Could not prepare SQL statement.";
     }

     // redirect the user
     header("Location: news.php");
    }

     }
     // if the form hasn't been submitted yet, show the form
     else
     {
     renderForm();
     }
     }

     // close the mysqli connection
     $conn->close();
     ?>
     </td>
     </tr>
     <?php
     include("includes/footer.inc.php"); 
     ?>


尝试增加php.ini中的内存限制。默认设置为128MB。

小错误可能导致大问题

if($stmt = $conn->prepare("SELECT ID, title, summary, entry FROM news WHERE ID=?"))
{
    $stmt->bind_param("i", $id); // <-- this is the problem
    $stmt->execute();


确保您的
条目
列不是长文本。我把我的从长文本改为中文本,它解决了同样的问题


MySQL v5.6.33

请将您的代码编辑到您的问题中。如果在每行的开头添加4个空格,它将保持其格式。1,2,3,4,对不起,我放弃了第140行是什么?第140行是这一行:'code'$stmt->bind_result($id,$title,$summary,$entry);它位于“编辑记录”部分,在更新行之后。我将它添加到pastebin,其他人编辑了它。我把它放在pastebin上,因为它显示了线条。你看到的是它在我的记事本上的格式++你真的想让我在200多行中添加4个空格吗?我添加了4个空格。有帮助吗?我试过了,不管我放多大,它都会用光。如果是那样的话,请查看你的内存使用情况。。如果有足够的内存为您的php服务。。。阅读这篇文章,可能会有助于你在回答之前读得更好一些。问题本身已经表明,限制设置为500mb,因此OP显然知道在哪里可以找到该选项。我尝试了许多上限和下限,但实际上,限制是什么并不重要。但正如Blizz善意地指出的,似乎我在绑定部分失败了,所以它试图选择整个表,而不是表太大。使用1代替I会导致另一个错误,并且仍然会泄漏内存。但是:id导致错误:无法准备SQL语句请确保更正所有语句。。。我认为如果我解释我对php有一些经验会有所帮助,但在大多数情况下我是一个新手。另外,近两周来,我一直盯着看,试图找出我做错了什么。哈哈,所以你的陈述找到并纠正我所有的陈述并不一定有帮助D
$stmt = $conn->prepare("SELECT ID, title, summary, entry FROM news WHERE ID=:id")
$stmt->bind_param(":id", $id);
$stmt = $conn->prepare("SELECT ID, title, summary, entry FROM news WHERE ID=?")
$stmt->bind_param(1, $id);