我一直在编写一个 php 脚本,以利用几个不同的提交按钮来更新、编辑和删除 SQL 数据库中的表信息。最近我一直收到这个错误。
致命错误:第 46 行 /home/peroral/public_html/InsertProducts.php 中允许的内存大小为 134217728 字节已用尽(尝试分配 30720 字节)
我曾尝试ini_set("memory_limit","128M");
在我的 php 文件中使用它以使其工作,但无论我分配多少内存(我已经达到 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>
?>