robtri Posted June 19, 2009 Share Posted June 19, 2009 hi, very new to this php and ajax world, just learning it as a personal project... I am currently trying to put together two drop down menu items, of car makes and when a make is selected it picks a model.. here's the code I have for both files <html> <head> <title>Selentry5 test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getModel(strURL) { var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('citydiv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body> And for findmodel.php <?php include ("dbconnect.php"); doDB(); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $make=$_REQUEST['make']; $query="select model from car_makes where car_make=$make"; $result=mysql_query($query); ?> <select name="model"> <option>Select Model</option> <? while($row=mysql_fetch_array($result)) { ?> <option value><?=$row['car_model']?></option> <? } ?> </select> when I load this, it produces the two drop down boxes but I get nothing in the model drop down?????? any help on this will really be appreciated... Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 20, 2009 Share Posted June 20, 2009 Change $row['car_model'] to $row['model']. You may want to put single quotes around $make in your SQL. Quote Link to comment Share on other sites More sharing options...
robtri Posted June 22, 2009 Author Share Posted June 22, 2009 thanks, appreciate that, tried it out and still no joy.... Quote Link to comment Share on other sites More sharing options...
xtopolis Posted June 23, 2009 Share Posted June 23, 2009 I highly recommend changing all of your short tags (<? ?>) to proper tags (<?php ?>) as using short tags is considered bad practice. I think this block should be modified to: <select name="model"> <option>Select Model</option> <?php while($row=mysql_fetch_array($result)) { echo '<option value="' . $row['car_model'] . '">' . $row['car_model'] . '</option>'; } ?> </select> That may not change anything however, but I also don't see where you call getModel() anywhere? It's defined, but not called in the code you have. Quote Link to comment Share on other sites More sharing options...
djjjozsi Posted June 30, 2009 Share Posted June 30, 2009 if you expected a string as a condition use the apostrofes around the data like: $query=sprintf("select * from car_makes where car_make='%s'" , mysqli_real_escape_string($make); Lets select that field which you're using on the following codes. you have opened a mysqli connecttion, but then you should use the mysqli_query() on this select, not the mysql_query Quote Link to comment 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.