cleary1981 Posted June 30, 2008 Share Posted June 30, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/ Share on other sites More sharing options...
DeanWhitehouse Posted June 30, 2008 Share Posted June 30, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578141 Share on other sites More sharing options...
cleary1981 Posted June 30, 2008 Author Share Posted June 30, 2008 I tried that and it didn't do anything. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578152 Share on other sites More sharing options...
DeanWhitehouse Posted June 30, 2008 Share Posted June 30, 2008 Is mod_desc definetly a row? try adding error_reporting(E_ALL); to the top of the script Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578158 Share on other sites More sharing options...
cleary1981 Posted June 30, 2008 Author Share Posted June 30, 2008 it is definatley a row in the module table. I tried adding that line to the php script but it did nothing. Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578163 Share on other sites More sharing options...
DeanWhitehouse Posted June 30, 2008 Share Posted June 30, 2008 can u post the current code with changes you made. Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578166 Share on other sites More sharing options...
cleary1981 Posted June 30, 2008 Author Share Posted June 30, 2008 <!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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578168 Share on other sites More sharing options...
AndyB Posted June 30, 2008 Share Posted June 30, 2008 I tried ... but it did nothing. You need to provide a far better description than that. Did you get an error? Did you get a blank white screen? Did you try to display the actual query string and check it's what you thought it was going to be? Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578170 Share on other sites More sharing options...
cleary1981 Posted June 30, 2008 Author Share Posted June 30, 2008 when i say it did nothing i mean that the page displayed as normal no error message. The onchange did not affect the page in any way. Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578171 Share on other sites More sharing options...
DeanWhitehouse Posted June 30, 2008 Share Posted June 30, 2008 then thats a js problem, not php Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578192 Share on other sites More sharing options...
cleary1981 Posted June 30, 2008 Author Share Posted June 30, 2008 I have changed the span i was using to display my result to a textarea. When the onchange runs now im getting 'undefined'. This is php i think Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578203 Share on other sites More sharing options...
revraz Posted June 30, 2008 Share Posted June 30, 2008 onchange is JS Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578206 Share on other sites More sharing options...
cleary1981 Posted June 30, 2008 Author Share Posted June 30, 2008 its the js that runs my php code Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578209 Share on other sites More sharing options...
revraz Posted June 30, 2008 Share Posted June 30, 2008 Undefined means just that. The variable you are trying to use is not defined. Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578218 Share on other sites More sharing options...
DeanWhitehouse Posted June 30, 2008 Share Posted June 30, 2008 Have you tried running the php code on it's own to see if it works, as this isn't a php problem so it should be moved to the js forum. Quote Link to comment https://forums.phpfreaks.com/topic/112573-why-wont-this-work/#findComment-578226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.