Jump to content

Recommended Posts

I have written a script that should display a discription that is stored in a db for each item in a dropown list. problem is that it doesnt update the description. Heres my html code

 

<script type="text/javascript" 
        src="prototype.js"></script>
<script type="text/javascript"
        src="scriptaculous.js"></script>
<script language="javascript" src="list.php"></script>
<script type="text/javascript" src="getdimensions.js"> </script>

<script type="text/javascript" 
        src="description.js"></script>

<script type="text/javascript">
window.onload = function() {
     new Draggable('object', {snap:25} );
fillCategory();
}

var request = null;

try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
	request = null;
	}

}
}
if (request == null)
alert("Error creating XMLHttp Request!");

function get_description() {
var model = document.getElementById("model").value;
var url = "lookupdescription.php?model=" + escape(model);
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}

function updatePage() {
if (request.readyState == 4) {
var description = request.reponseText;
document.getElementById("description").value = description;

}
}

</script>


</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<div id="container">
<div id="top">
	<h1>TES - Pricing System (Design Mode)</h1>
</div>

<div id="leftSide">
	<fieldset>
	<legend>Module</legend>
	<FORM name="drop_list">
	<label for="type">Type</label>
	<div class="div_texbox">
		<SELECT  NAME="Category" onChange="SelectSubCat();" >
		<Option value="">Select Type</option>
		</SELECT>
	</div>
  		<label for="mod_named">Model</label>
    		<div class="div_texbox">
		<SELECT id="model" NAME="SubCat" onChange="get_description();">
		<Option value="">Select Model</option>
		</SELECT>
	</div>
	<fieldset>
	<legend>Description</legend>
	<span id="description">description goes here</description>
	</fieldset>
	<label for="mod_name">Name</label>
    		<div class="div_texbox">
    			<input name="username" type="text" class="username" id="username" value="" />
	</div>
	<div class="button_div">
		<input name="Submit" type="button" value="Generate" class="buttons" onClick="generate_module()"/>
	</div>
	</form>
	</fieldset>

	<fieldset>
	<fieldset>
	<legend>Delete</legend>
	</fieldset>
	<fieldset>
	<legend>Generated Module</legend>
	<img id="object">
	</fiedset> 
	</fieldset>	
</div>


<div id="content">
	<div id="drop_area">

	</div>
</div>  

  	<div class="clear"></div>
</div>

</body>
</html>

 

 

and my php

 

<?php

require "config.php";

$type = $_REQUEST['model'];
$select = 'SELECT mod_desc';
$from = ' FROM module';
$where = ' WHERE type = \'' .$type' . '\'';

$queryResult = @mysql_query($select . $from . $where);
if (!queryResult)
die('Error retrieving description from the database');

while ($row = mysql_fetch_array($queryResult)) {
echo $row['mod_desc'];
}

mysql_close($conn);
?>

Link to comment
https://forums.phpfreaks.com/topic/112573-why-wont-this-work/
Share on other sites

Try this, and see if there is an error in your statement

<?php

 

require "config.php";

 

$type = $_REQUEST['model'];

$select = 'SELECT mod_desc';

$from = ' FROM module';

$where = ' WHERE type = \'' .$type' . ''';

 

$queryResult = mysql_query($select . $from . $where) or die("Error!".mysql_error());

while ($row = mysql_fetch_array($queryResult)) {

echo $row['mod_desc'];

}

 

mysql_close($conn);

?>

Link to comment
https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578141
Share on other sites

<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>TES - Pricing System</title>
<link rel="stylesheet" type="text/css"
href="style.css" />
<script src="ShowDescription.js">
</script>
<script type="text/javascript" 
        src="prototype.js"></script>
<script type="text/javascript"
        src="scriptaculous.js"></script>
<script language="javascript" src="list.php"></script>
<script type="text/javascript" src="getdimensions.js"> </script>

<script type="text/javascript" 
        src="description.js"></script>

<script type="text/javascript">
window.onload = function() {
     new Draggable('object', {snap:25} );
fillCategory();
}

var request = null;

try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
	request = null;
	}

}
}
if (request == null)
alert("Error creating XMLHttp Request!");

function get_description() {

var model = document.getElementById("model").value;
var url = "lookupdescription.php?model=" + escape(model);
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}

function updatePage() {
if (request.readyState == 4) {
var description = request.reponseText;
document.getElementById("description").value = description;

}
}

</script>


</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<div id="container">
<div id="top">
	<h1>TES - Pricing System (Design Mode)</h1>
</div>

<div id="leftSide">
	<fieldset>
	<legend>Module</legend>
	<FORM name="drop_list">
	<label for="type">Type</label>
	<div class="div_texbox">
		<SELECT  NAME="Category" onChange="SelectSubCat();" >
		<Option value="">Select Type</option>
		</SELECT>
	</div>
  		<label for="mod_named">Model</label>
    		<div class="div_texbox">
		<SELECT id="model" NAME="SubCat" onChange="get_description();">
		<Option value="">Select Model</option>
		</SELECT>
	</div>
	<fieldset>
	<legend>Description</legend>
	<span id="description">description goes here</description>
	</fieldset>
	<label for="mod_name">Name</label>
    		<div class="div_texbox">
    			<input name="username" type="text" class="username" id="username" value="" />
	</div>
	<div class="button_div">
		<input name="Submit" type="button" value="Generate" class="buttons" onClick="generate_module()"/>
	</div>
	</form>
	</fieldset>

	<fieldset>
	<fieldset>
	<legend>Delete</legend>
	</fieldset>
	<fieldset>
	<legend>Generated Module</legend>
	<img id="object">
	</fiedset> 
	</fieldset>	
</div>


<div id="content">
	<div id="drop_area">

	</div>
</div>  

  	<div class="clear"></div>
</div>

</body>
</html>

 

 

<?php

require "config.php";
error_reporting(E_ALL);

$type = $_REQUEST['model'];
$select = 'SELECT mod_desc';
$from = ' FROM module';
$where = ' WHERE type = \'' .$type' . ''';

$queryResult = mysql_query($select . $from . $where) or die("Error!".mysql_error());
while ($row = mysql_fetch_array($queryResult)) {
echo $row['mod_desc'];
}


mysql_close($conn);
?>

Link to comment
https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578168
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.