PDA

View Full Version : lỗi Fatal error: Allowed memory size of 134217728 bytes exhausted và đường dẫn



thientanchuong
20-06-2012, 05:43
Mình tạo ra 4 file khác nhau:

index.php = > chứa đường dẫn include với body.php và menu.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="CSS/myform.css" />
<title>Ebay Management System</title>

</head>

<body background="image/VietMartBackground.jpg">
<table width="100%" border="1">
<tr>
<td>
<form name="FormSearch" action="../function/searchProcess.php" method="post" />
<input name="searchText" title="searchText" type="text" width="400"/>
<input name="SearchButton" title="SearchButton" Type="Submit" value="Search"/>
</form>
</td>
</tr>
<tr>
<td>
<?php
include 'template/menu.php';
?>
</td>
</tr>
<tr>
<td>
<?php
include 'template/body.php';
?>
</td>
</tr>
</table>
</body>
</html>


menu.php => nằm trong folder template


<link rel="stylesheet" type="text/css" href="../CSS/menu.css" />

<ul id="nav">
<li>
<a href="index.php?page=body">Home</a>
</li>

<li>
<a href="#">Supplier</a>
<ul>
<li><a href="index.php?page=supplierAdd" name="supplierAdd">Add New Suppliers</a></li>
<li><a href="index.php?page=supplierList" name="supplierList">List All Suppliers</a></li>
</ul>
</li>
<li>
<a href="#">Items</a>

<ul>
<li><a href="index.php?page=itemAdd" name="itemAdd">Add New Items</a></li>
<li><a href="index.php?page=itemList" name="itemList">List All Items</a></li>
</ul>

</li>
<li>
<a href="#">Catalogue</a>
<ul>
<li><a href="index.php?page=catalogueAdd" name="catalogueAdd">Add New Catalogue</a></li>
<li><a href="index.php?page=catalogueList" name="catalogueList">List All Catalogues</a></li>
</ul>
</li>
<li>
<a href="#">Ebay Sale</a>
<ul>
<li><a href="index.php?page=dailySaleRecords" name="dailySaleRecords">Daily Sale Records</a></li>
<li><a href="index.php?page=totalProfitChecking" name="totalProfitChecking">Total Profit Checking</a></li>
</ul>
</li>
<li>
<a href="#">Ebay Problem Collection</a>
<ul>
<li><a href="index.php?page=problemAdd" name="problemAdd">Add New Problems</a></li>
<li><a href="index.php?page=problemList" name="problemList">List All Problems</a></li>
</ul>
</li>
</ul>


menu.css => nằm trong folder CSS


/*------------------------------------*\
NAV
\*------------------------------------*/
#nav{
list-style:none;
font-weight:bold;
margin-bottom:10px;
/* Clear floats */
float:left;
width:100%;
/* Bring the nav above everything else--uncomment if needed.
position:relative;
z-index:5;
*/
}
#nav li{
float:left;
margin-right:10px;
position:relative;
}
#nav a{
display:block;
padding:5px;
color:#fff;
background:#333;
text-decoration:none;
}
#nav a:hover{
color:#fff;
background:#6b0c36;
text-decoration:underline;
}

/*--- DROPDOWN ---*/
#nav ul{
background:#fff; /* Adding a background makes the dropdown work properly in IE7+.
Make this as close to your page's background as possible (i.e. white page == white background). */
background:rgba(255,255,255,0); /* But! Let's make the background fully transparent where we can, we don't actually want to see it if we can help it... */
list-style:none;
position:absolute;
left:-9999px; /* Hide off-screen when not needed (this is more accessible than display:none;) */
}
#nav ul li{
padding-top:1px; /* Introducing a padding between the li and the a give the illusion spaced items */
float:none;
}
#nav ul a{
white-space:nowrap; /* Stop text wrapping and creating multi-line dropdown items */
}
#nav li:hover ul{ /* Display the dropdown on hover */
left:-40px; /* Bring back on-screen when needed */
}
#nav li:hover a{ /* These create persistent hover states, meaning the top-most link stays 'hovered' even when your cursor has moved down the list. */
background:#6b0c36;
text-decoration:underline;
}
#nav li:hover ul a{ /* The persistent hover state does however create a global style for links even before they're hovered. Here we undo these effects. */
text-decoration:none;
}
#nav li:hover ul li a:hover{ /* Here we define the most explicit hover states--what happens when you hover each individual link. */
background:#333;
}


body.php => chứa SWITCH CASE code.


<?php
$page = isset($_GET['page']) ?$_GET['page'] : 1;
switch ($page){
case "supplierAdd":
include("supplierAdd.php");
break;
case "supplierList":
include("supplierList.php");
break;

case "itemAdd":
include("itemAdd.php");
break;
case "itemList":
include("itemList.php");
break;

case "catalogueAdd":
include("catalogueAdd.php");
break;
case "catalogueList":
include("catalogueList.php");
break;

case "dailySaleRecords":
include("dailySaleRecords.php");
break;
case "totalProfitChecking":
include("totalProfitChecking.php");
break;

case "problemAdd":
include("problemAdd.php");
break;
case "problemList":
include("problemList.php");
break;

default:
include ("body.php");

}

?>


ở đây, mình có tới 2 trường hợp xảy ra lỗi

1/ Trường hợp 1 có 2 lỗi

Lỗi ko hiển thị kiểu dáng menu

http://img713.imageshack.us/img713/2040/menuerror.jpg

nhưng các đường truyền đều ok hết ko bị lỗi

lỗi báo ở index.php


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 6144 bytes) in D:\xampp\htdocs\EBAY\template\body.php on line 40

=> cái này làm sao sửa lỗi đây bạn.

2/ Lỗi báo ở đường truyền

Nếu mình ko thông qua index.php mà bật ngay menu.php thì có giao diện đúng như mình muốn
http://img12.imageshack.us/img12/7608/menudq.jpg

nhưng sau đó bấm vào bất kì trên menu thì nó báo OBJECT NOT FOUND

http://img535.imageshack.us/img535/7936/duongtruyenerror.jpg

Làm sao sửa các lỗi trên vậy các bạn

liemdo
22-06-2012, 06:35
Trong file body .php, ban de la "include ("body .php")". Nhu vay file body .php trong nhieu truong hop se include chinh no, roi file body .php duoc include lai include mot file body .php khac nua... Do vay ma moi het memory.

thientanchuong
24-06-2012, 04:13
Mình trình bày dữ liệu trong supplier, nếu chưa có thì báo tin còn có thì liệt kê ra nhưng bị báo lỗi ở dòng

Nhưng mà trong dữ liệu trong supplier của mình chưa có data nào cả vậy mà nó cũng ko báo tin gì luôn. Làm sao bắt nó báo tin đây bạn

đây là code của trang

<?php
error_reporting();
$listSQL = "SELECT * FROM supplier";
$listQuery = mysql_query ($listSQL, $con);
$listResult = mysql_fetch_assoc ($listQuery);

while ($listResult){
if ($listResult = ""){
echo "NO record in the database";
} else {
echo'<table width="100%" border="1">';
'<tr>';
'<td width="11%">Supplier Number</td>';
'<td width="77%">{$row["supplierID"]}</td>';
'<td width="12%">More Information</td>';
'</tr><tr>';
'<td>Supplier Name</td>';
'<td>{$row["supplierName"]}</td>';
'<td>Edit</td>';
'</tr>';
'<tr>';
'<td>Supplier Service</td>';
'<td>{$row["supplierService"]}</td>';
'<td>Delete</td>';
'</tr>';
'</table>';
}
}
mysql_close($con);
?>
Ngoài ra khi khi trang index.php ra thì hiện ra lỗi


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 6144 bytes) in D:\xampp\htdocs\ebay\TEMPLATE\display.php on line 13

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>EBAY MANAGEMENT SYSTEM</title>
<link rel="stylesheet" type="text/css" href="CSS/menu.css" />
<link rel="stylesheet" type="text/css" href="CSS/dataForm.css" />
</head>
<?php
error_reporting();
require_once ("FUNCTION/connect.php");
?>
<body>
<table width="100%" border="1">
<tr>
<td colspan="2">
<form name="searchForm" action="" method="post">
<input name="searchText" type="text" width="100" />
<input name="searchSubmit" type ="Submit" value="Search" />
</form>
</td>
</tr>
<tr>
<td colspan="2">
<?php
include ("TEMPLATE/menu.php");
?>
</td>
</tr>
<tr>
<td width="75%">
<?php
include ("TEMPLATE/display.php");
?>
</td>
<td width="25%">&nbsp;</td>
</tr>
</table>
</body>
</html>

sao lại báo là quá tải bộ nhớ ??? làm sao khắc phục được ???

Mong bạn giúp đỡ dùm, thanks a lot

antipro.vn
24-06-2012, 18:35
Đầu tiên, lỗi không hiển thị css là do bạn đặt ID bị sai.
Trong css của bạn là

#nav ul ...
nghĩa là ul phải nằm trong 1 cái thẻ có ID là nav, trong khi code html của bạn là

<ul id="nav" ...
Để sửa, bạn đặt cái thẻ parent của thẻ ul đó, đặt cho nó id là nav. Đơn giản là wrap cái ul của bạn thành thế này

<div id="nav">
<ul>
...
</ul>
</div>

Ngoài ra khi bạn vào trang index thì -> đường dẫn tới file css của bạn bị sai. Bạn hãy thay bằng đường dẫn tuyệt đối (từ tên miền) hoặc đường dẫn tương đối với file index.php
Mình nghĩ chỗ đó nên thay thành thế này
<link rel="stylesheet" type="text/css" href="./CSS/menu.css" />
-> thay 2 dấu chấm bằng 1 dấu chấm (xin lỗi mình chưa đủ post để trích bài ..., ddth vô đối)

--------------------------------
Còn lỗi php của bạn là do bạn xài dòng này


while ($listResult)

mà cuối dòng lặp, bạn không lấy row data khác cho nó
Cụ thể thì code của bạn sẽ có dạng thế này


while ($listResult)
{
//code cũ của bạn ở đây

//thêm dòng này vào
$listResult = mysql_fetch_assoc ($listQuery);
}


Xin nói thêm là code cũ của bạn chỗ dòng này


if ($listResult = ""){ //1 dấu bằng

nên đổi thành thế này


if ($listResult == ""){ //2 dấu bằng để so sánh


Mình sửa lại nội dung file supplier như thế này


<?php
error_reporting();
$listSQL = "SELECT * FROM supplier";
$listQuery = mysql_query ($listSQL, $con);

if(!mysql_num_rows($listQuery)){
echo "NO record in the database";
}

while ($listResult= mysql_fetch_assoc ($listQuery)){ //thường khi dùng mysql_fetch_assoc hay array ... người ta thường loop như thế này
//if ($listResult == ""){ //dòng này thực ra không cần
// echo "NO record in the database";
//} else {
echo'<table width="100%" border="1">';
'<tr>';
'<td width="11%">Supplier Number</td>';
'<td width="77%">{$row***91;"supplierID"***93;}</td>';
'<td width="12%">More Information</td>';
'</tr><tr>';
'<td>Supplier Name</td>';
'<td>{$row["supplierName"]}</td>';
'<td>Edit</td>';
'</tr>';
'<tr>';
'<td>Supplier Service</td>';
'<td>{$row["supplierService"]}</td>';
'<td>Delete</td>';
'</tr>';
'</table>';
//}
}
mysql_close($con);


Welcome to PHP. Thẻ PHP trong ddth bị lỗi (lâu rồi) nên mình dùng thẻ code để bạn dễ copy.
Khi thấy thông báo lỗi như vầy:


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 6144 bytes) in __FILE__ __LINE__0

--> thì lỗi vòng lặp nó xảy ra ở line đó đó. Lỗi Allowed memory size of 134217728 bytes exhausted thường xảy ra khi bạn dùng dòng lặp mà nó rơi vào trường hợp vô hạn hoặc dùng đệ quy mà cũng bị đệ quy vô hạn. Ví dụ


while(true){
}

hoặc


function a(){
b();
}
function b(){
a();
}
a(); // lỗi

thientanchuong
27-06-2012, 12:34
tuyệt quá, cám ơn bạn antipro.vn nhìu lém