deemi_pk Posted August 31, 2010 Share Posted August 31, 2010 Hi how r u. i hope u all r fine i need some help, i creat a company table there is comp_name; comp_adres; comp_country; comp_city. i creat an ajax file that when i chose country their related city come cities come successfully but when i want save it all data save in mysql else city i dont know what to do i past my script so please help me. Country Table CREATE TABLE IF NOT EXISTS `tbl_country` ( `cont_id` int(11) NOT NULL AUTO_INCREMENT, `cont_name` varchar(100) NOT NULL, PRIMARY KEY (`cont_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; -- -- Dumping data for table `tbl_country` -- INSERT INTO `tbl_country` (`cont_id`, `cont_name`) VALUES (2, 'Pakistan'), (4, 'Saudi Arabia'), (5, 'Spain'); City Table CREATE TABLE IF NOT EXISTS `tbl_city` ( `city_id` int(11) NOT NULL AUTO_INCREMENT, `city_name` varchar(100) NOT NULL, `city_country` int(11) NOT NULL, PRIMARY KEY (`city_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ; -- -- Dumping data for table `tbl_city` -- INSERT INTO `tbl_city` (`city_id`, `city_name`, `city_country`) VALUES (1, 'Islamabad', 2), (2, 'Lahore', 2), (3, 'Karachi', 2), (4, 'Peshawar', 2), (5, 'Quetta', 2), (6, 'Riyadh', 4), (7, 'Gujranwala', 2), (8, 'Jaddah', 4), (9, 'Makkah', 4), (10, 'Madinah', 4), (12, 'Faisalabad', 2), (17, 'Hyderabad', 2), (18, 'Madrid', 5), (19, 'Cordoba', 5), (22, 'Granada', 5), (23, 'Toledo', 5); Company Table CREATE TABLE IF NOT EXISTS `tbl_company` ( `comp_id` int(11) NOT NULL AUTO_INCREMENT, `comp_name` varchar(100) NOT NULL, `comp_adres` varchar(100) NOT NULL, `comp_country` int(11) NOT NULL, `comp_city` int(11) NOT NULL, PRIMARY KEY (`comp_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ; -- -- Dumping data for table `tbl_company` -- INSERT INTO `tbl_company` (`comp_id`, `comp_name`, `comp_adres`, `comp_country`, `comp_city`) VALUES (1, 'Interactive Production', 'Trust Plaza 70-B', 2, 2), (3, 'PMS', 'Model Town', 2, 7), (7, 'im Logic', 'ByPass', 2, 3), (8, 'Young Spiders', 'Hall Road', 5, 19), (9, 'JJ', 'Gill Road', 4, 0), (15, 'df', 'dfgg', 2, 0), (16, 'df', 'dfgg', 2, 0), (17, 'sdfsdf', 'sdfsdf', 4, 0); Ajax File with HTML <script type="text/javascript" language="javascript"> function showCountry(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getCity.php?q="+str,true); xmlhttp.send(); } </script> <table width="100%" border="0" cellspacing="2" cellpadding="2" align="center"> <tr> <td colspan="2" class="heading" align="center">Add Company</td> </tr> <tr> <td> </td> </tr> <tr> <td class="loginText">Company Name :</td> <td> <input type="text" name="txtCompname" id="txtCompname" maxlength="70" size="40" style="padding-left:6px;" /> </td> </tr> <tr> <td class="loginText">Company Address :</td> <td> <input type="text" name="txtCompadres" id="txtCompadres" maxlength="100" size="40" style="padding-left:6px;" /> </td> </tr> <tr> <td class="loginText">Select Country :</td> <td> <select name="selectCountry" id="selectCountry" onchange="showCountry(this.value)"> <option value="0"> >--- Select Country ---< </option> <?php $id = 'Select * From tbl_country'; $qry = mysql_query($id); echo mysql_num_rows($qry); while($row = mysql_fetch_array($qry)) { ?> <option value="<?php echo $row['cont_id']; ?>"> <?php echo $row['cont_name']; ?></option> <?php } ?> </select> </td> </tr> <tr> <td class="loginText">Select City :</td> <td><div id="txtHint">City</div></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2" class="submit" align="right"> <input type="submit" name="subComp" id="subComp" value="Save Company" style="margin-right:32px;" /> </td> </tr> </table> getCity.php <?php require('db.php'); $q = intval($_GET['q']); ?> <form name="frmCity" id="frmCity" method="post" action="addCompany.php"> <select name="selCity" id="selCity"> <option value="0"> >--- Select City ---< </option> <?php $id = 'Select * From tbl_city Where city_country='.$q; $qry = mysql_query($id); while($row = mysql_fetch_array($qry)) { ?> <option value="<?php echo $row['city_id']; ?>"><?php echo $row['city_name']; ?></option> <?php } ?> </select> </form> Please Help me and tell me wat can i do and where can i put Quote Link to comment https://forums.phpfreaks.com/topic/212142-help-for-php-mysql-and-ajax/ 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.