Jump to content


Photo

mySQL fatal error, PHP infinite loop...need advice


  • Please log in to reply
2 replies to this topic

#1 aeafisme23

aeafisme23
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts
  • LocationUSA

Posted 08 August 2006 - 05:27 PM

SQL DUMP: http://www.kindervis...ydwayne/sql.txt

Any advice would rock!!! Thanks all that read!

Error Message:
Fatal error: Allowed memory size of 18388608 bytes exhausted (tried to allocate 11520 bytes) in /home2/admin/etc-www/etc/etc.php on line 12

Problem:
When clicking submit I add infinite enteries to the database.
I need to find a way to insert from my form to how my database is setup so that it adds correct enteries and id's. Note the form has 3 sql queries because each input updates to a different table in the database. Once populated the chained select will show all enteries. I have provided a picture of the database tables, the first few enteries were manually entered in mySQL and works, but if i do it through a form it loops. I will produce codes to both the form and the chained select.  I understand that the DB structure is jank and need a know how to setup correctly. I believe that the default 0 should go but i know it wont solve problem completely in its entirety.

Posted Image

Code: (ADD.php) This is the form

<?php
if ($submit) {
  // process form
$db = mysql_connect("www.domain.org", "user", "pass");
mysql_select_db("database_org",$db);
// Write the queries
$sql = "INSERT INTO make (make_id, make) VALUES ('$make_id','$make')";
$sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')";
$sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')";

// Execute the queries
mysql_query($sql) or die(mysql_error());
mysql_query($sql2) or die(mysql_error());
mysql_query($sql3) or die(mysql_error());
  
  $result = mysql_query($sql); 
  $result = mysql_query($sql2); 
  $result = mysql_query($sql3); 
  require("add.php"); 
  echo('thank you for your add');
} else{
  ?>
  

<table width="720" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
  <tr> 
    <td valign="top" bgcolor="ffffff">
<FORM NAME=submit method="post" action="<?php echo $PHP_SELF?>">
		<TABLE>
		  <tr>
			<td width="140"><LABEL><b>Make:</b></LABEL></td>
			<td width="550"><INPUT TYPE=text NAME="make" ID="make" SIZE="35" MAXLENGTH="60"></td>
			<td width="10">&nbsp;</td>
		  </tr>
		</TABLE>
		<TABLE>
		  <tr>
			<td width="140"><LABEL><b>Model:</b></LABEL></td>
			<td width="550"><INPUT TYPE=text NAME="model" ID="model" SIZE="35" MAXLENGTH="60"></td>
			<td width="10">&nbsp;</td>
		  </tr>
		</TABLE>	
		<TABLE>
		  <tr>
			<td width="140"><LABEL><b>Sub-Model:</b></LABEL></td>
			<td width="550"><INPUT TYPE=text NAME="submodel" ID="submodel" SIZE="35" MAXLENGTH="60"></td>
			<td width="10">&nbsp;</td>
		  </tr>
		</TABLE>											
		<TABLE>
		  <tr>
			<td width="140">&nbsp;</td>
			<td width="550"><INPUT TYPE="Submit" NAME="submit" VALUE="Submit"></td>
			<td width="10">&nbsp;</td>
		  </tr>
		</TABLE>
</form>
<?php
} // end if

?>

Chained Select
<?php
$dbservertype='mysql';
$servername='localhost';
// username and password to log onto db server
$dbusername='user';
$dbpassword='pass';
// name of database
$dbname='domain_org';

////// DONOT EDIT BELOW  /////////
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
?>
<html>

<head>
<title>Year/Make/Model Multiple DD - Populated from  Form</title>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.make.options[form.make.options.selectedIndex].value; 
self.location='dd3.php?make=' + val ;
}
function reload3(form)
{
var val=form.make.options[form.make.options.selectedIndex].value; 
var val2=form.model.options[form.model.options.selectedIndex].value; 

self.location='dd3.php?make=' + val + '&submodel=' + val2 ;
}

</script>
</head>

<body>
<?


///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT make,make_id FROM make order by make"); 
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
$cat=$HTTP_GET_VARS['make']; // This line is added to take care if your global variable is off
if(isset($make) and strlen($make) > 0){
$quer=mysql_query("SELECT DISTINCT model,model_id FROM model where make_id=$make order by model"); 
}else{$quer=mysql_query("SELECT DISTINCT model,model_id FROM model order by model"); } 
////////// end of query for second subcategory drop down list box ///////////////////////////


/////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///// 
$cat3=$HTTP_GET_VARS['submodel']; // This line is added to take care if your global variable is off
if(isset($submodel) and strlen($submodel) > 0){
$quer3=mysql_query("SELECT DISTINCT submodel FROM submodel where model_id=$submodel order by submodel"); 
}else{$quer3=mysql_query("SELECT DISTINCT submodel FROM submodel order by submodel"); } 
////////// end of query for third subcategory drop down list box ///////////////////////////


echo "<form method=post name=f1 action='retrieve.php'>";
//////////        Starting of first drop downlist /////////
echo "<select name='make' onchange=\"reload(this.form)\"><option value=''>Select Make</option>";
while($noticia2 = mysql_fetch_array($quer2)) { 
if($noticia2['make_id']==@$make){echo "<option selected value='$noticia2[make_id]'>$noticia2[make]</option>"."<br>";}
else{echo  "<option value='$noticia2[make_id]'>$noticia2[make]</option>";}
}
echo "</select><br><br>";
//////////////////  This will end the first drop down list ///////////

//////////        Starting of second drop downlist /////////
echo "<select name='model' onchange=\"reload3(this.form)\"><option value=''>Select Model</option>";
while($noticia = mysql_fetch_array($quer)) { 
if($noticia['model_id']==@$submodel){echo "<option selected value='$noticia[model_id]'>$noticia[model]</option>"."<br>";}
else{echo  "<option value='$noticia[model_id]'>$noticia[model]</option>";}
}
echo "</select><br><br>";
//////////////////  This will end the second drop down list ///////////


//////////        Starting of third drop downlist /////////
echo "<select name='submodel' ><option value=''>Select Submodel</option>";
while($noticia = mysql_fetch_array($quer3)) { 
echo  "<option value='$noticia[submodel]'>$noticia[submodel]</option>";
}
echo "</select><br><br>";
//////////////////  This will end the third drop down list ///////////

echo "<input type=submit value=Submit>";
echo "</form>";
?>


#2 aeafisme23

aeafisme23
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts
  • LocationUSA

Posted 11 August 2006 - 02:44 PM

I am just refreshing this item, I will make sure this is the last so others have a chance as well, just seeing if anyone has any input today it would be much appreciated :)

#3 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 11 August 2006 - 03:41 PM

you require("add.php"); in add.php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users