2013-04-26 71 views
0

我一直在研究PHP脚本,利用几个不同的提交按钮来更新,编辑和删除SQL数据库中的表信息。最近我一直在收到这个错误。调试我无法修复的错误

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 30720 bytes) in /home/peroral/public_html/InsertProducts.php on line 46

我曾经试图得到它的工作在我的PHP文件中使用ini_set("memory_limit","128M");试过了,但没关系,我是多么的内存分配(我已经上涨到512)我仍然得到错误。有没有人有任何建议让我的脚本工作?

这是我的代码。

<!DOCTYPE html> 
<html lange="en"> 

<!--orders.php--> 

<html> 
<head> 
<title> InsertProducts.html form </title> 
<meta charset="utf-8"> 
</head> 
<body> 
<?php 
    ini_set("memory_limit","128M"); 
    require 'InsertProducts.php'; 
    $db = DB::connect('mysql://peroal:*******@localhost/peroral'); 

    if (DB::isError($db)) 
     {die("Cannot Connect " . $db->getMessage());} 

    extract($_POST);  


     if(isset($create)) 
      { 

      $q = $db->query("Create Table Products 
      id MEDIUMINT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), Product_Name VARCHAR (255), Product_Type VARCHAR (50), Product_Price DECIMAL (4,2), LOR INT"); 
      VALUES ('$Name', '$Type', $Price, $LOR); 
     if (!$q) 
       die("Unable to Create Table." . $q->getMessage()); 
     else 
       print("Table Was Created.<br />"); 
      } 

     else if(isset ($delete)) 
      { $q = $db ->query("DROP TABLE Products"); 

      if($q) 
       print("Table Products Was Deleted.<br />"); 
      else 
       print ("Unable to Delete Products Table.<br />"); 
      } 

     else if (isset ($add)) 
      { $q = $db ->query("INSERT INTO Products (Product_Name, Product_Type, Product_Price, LOR); 
       VALUES ('$name, $type, $price, $lor)"); 

      if(!$q) 
       print ("Query Failed.<br />"); 
      else 
       print ("Query Successful.<br />"); 
      } 
     else if (isset ($update)) 
      { $q = $db ->query ("UPDATE Product_Name, Product_Type, Product_Price, LOR"); 
      if(!q) 
       print ("Query Failed.<br />"); 
      else 
       print ("Query Successful.<br />"); 
      } 
     else if (isset ($display)) 
      { $sql = "SELECT Product_Name, Product_Type, Product_Price, LOR FROM products WHERE price >= $min_price 
       AND price <= $max_price AND Product_Name LIKE '$name'"; 
      if($LOR == 'Liquor') 
       $sql.='AND LOR=1'; 
      else 
       $sql.='AND LOR=0'; 
      } 
     print '<table>'; 
     print '<tr><th>Name</th><th>Type</th><th>Price</th><th>LOR</th>'; 
     while ($row =$q->fetchRow()) 
      { 
       $numberOfRows++; 
       if($row[3] ==1) 
       { 
       $LOR="Liquor"; 
       } 
       else 
       { 
       $LOR="Beer"; 
       } 
      print"<tr>"; 
      print"<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$LOR</td>"; 
      print "</tr>"; 
      } 
     print'</table>';  

     if($numberOfRows == 0) 
      print"No Match Found"; 
     ?> 

</body> 
</html>  



    ?> 
+0

你有GOOGLE上搜索,甚至一个解决方案吗?这已经被问了很多次了。 http://www.groovypost.com/howto/howto/how-to-solve-php-fatal-error-allowed-memory-size-of-8388608-bytes-exhausted/ – 2013-04-26 02:23:45

+0

这就是我得到ini_set(“memory_limit ”, “128M”);码。 – user2322110 2013-04-26 02:27:56

+3

请勿使用'extract($ _ POST)'。这真的很危险。黑客可以直接覆盖变量的代码 – hek2mgl 2013-04-26 02:28:18

回答

0

根据您的服务器/主机的配置方式,您的ini_set可能也可能不是可行的选项。

如果您有权访问php.ini文件,请改变那里的内存限制,它应该可以正常工作。

+0

我没有访问它,因为我没有访问任何服务器。 – user2322110 2013-04-26 03:39:02