Jump to content

File Internal Server Error on Dropdowns


dfowler

Recommended Posts

Hey guys, I'm trying to get some dynamic dropdowns to work, but keep getting this error.  Can somebody take a look at the code and tell me what I am doing wrong.  Thanks!

 

deletec.php

<?php
include 'system.php';

//FIRST list box
$query = "select * from categories";
$list1 = array();
$result=mysql_query($query);
while (($row = mysql_fetch_assoc($result)) !== false) {
	$list1[] = $row;
}
?>
<script type="text/javascript">

var AdminResponse = "";

function parseResponse(){

	var nText = AdminResponse.getElementsByTagName('optionText');
	var nVal = AdminResponse.getElementsByTagName('optionVal');
	document.forms[0]['group'].options.length = 1;
	for (i=0; i<nText.length; i++)
		{ 
		 var nOption = document.createElement('option'); 
		 var isText = document.createTextNode(nText[i].firstChild.data); 
		 nOption.setAttribute('value',nVal[i].firstChild.data); 
		 nOption.appendChild(isText); 
		 document.forms[0]['group'].appendChild(nOption); 
		}
}

function update(nVal){

	var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();   
	AdminRequest.onreadystatechange = function()
		{
	 	 if (AdminRequest.readyState == 4)
			{
	 	 	 if (AdminRequest.status == 200)
				{
		 	 	 AdminResponse = AdminRequest.responseXML;
		 	 	 parseResponse();
				}
	 	 	 else 	{
			 	 alert('Error update.php File '+ AdminRequest.statusText);
				}
			}
		}
	var infoStr = "?choice="+nVal;
	AdminRequest.open("GET", "update.php"+infoStr, true);
	AdminRequest.send(null); 
}

</script>

<form method="post" enctype="multipart/form-data" name="myForm" target="_self" action="deletec2.php">
<br />
<table cellpadding="3" cellspacing="3" border="0">
	<tr>
		<td>
			Category: <select name="list1" onchange="update(this.value)">
				<option value="0">Select Category</option>
				<?php 
				foreach($list1 as $l) { ?>
					<option value="<?php echo $l['id']; ?>"><?php echo $l['name']; ?></option>
				<?php } ?>
			</select>
			PDF: <select name="group">
				<option value=""> Make a selection </option>
			</select>
		</td>
	</tr>
	<tr>
		<td>
			<input type="submit" name="Submit" value="Submit" class="menu-next" />
		</td>
	</tr>
</table>
</form>

 

update.php

<?php 
include 'system.php';

$choice = $_GET['choice'];
$xml = "<?xml version='1.0' ?><options>";

$query = "SELECT * FROM cat_pdfs WHERE cat_id = '$choice'";
$cats = array();
$result = @mysql_query($query);
while (($row = mysql_fetch_assoc($result)) !== false) {
	$cats[] = $row;
}
pdfs = array();
foreach($cats as $c) {
	sql = "SELECT * FROM pdfs WHERE id='".$c['pdf_id']."'";
	$result2 = @mysql_query($sql);
	while (($row2 = mysql_fetch_assoc($result2)) !== false) {
		$pdfs[] = $row2;
	}
}
$num = @mysql_num_rows($result);
if ($result && $num > 0) {
 	 foreach($pdfs as $p) {
 	 	 $xml .= "<optionText>" . $p['name'] . "</optionText><optionVal>" . $p['id'] . "</optionVal>";
	}
}
       $xml .= "</options>";
@mysql_free_result($result);
@mysql_close();	
header("Content-Type: text/xml");
echo $xml;

?>

Link to comment
Share on other sites

Got it to work, here is the code:

<?php 
include 'system.php';

$choice = $_GET['choice'];
$xml = "<?xml version='1.0' ?><options>";

$query = "SELECT * FROM cat_pdfs WHERE cat_id = '$choice'";
$result = @mysql_query($query);
$num = @mysql_num_rows($result);
if ($result && $num > 0) {
 	 while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
		$sql = "SELECT * FROM pdfs WHERE id='".$row['pdf_id']."'";
		$result2 = @mysql_query($sql);
		$num2 = @mysql_num_rows($result2);
		if ($result2 && $num2 > 0) {
			while ($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)) {
 	 			$xml .= "<optionText>" . $row2['name'] . "</optionText><optionVal>" . $row2['id'] . "</optionVal>";
			}
		}
	}
}
       $xml .= "</options>";
@mysql_free_result($result);
@mysql_close();	
header("Content-Type: text/xml");
echo $xml;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.