sprint10s Posted May 24, 2009 Share Posted May 24, 2009 I am a beginner and not sure how to do this. Basically I have 2 tables i need to pull information from company and company_info I need to create a drop down box to show a list of the companies from the company table and when the user selects a company and hits submit it pulls out the name from the company table and all the fields in the company_info table. the Company_ID is the key the relates the two tables together. If someone can help me get started on where to start i would greatly appreciate it. I know eventually the info has to be put into a variable and then to echo the variable but not sure where to start. thanks in advance for any help given Link to comment https://forums.phpfreaks.com/topic/159442-retrieving-information-from-a-form/ Share on other sites More sharing options...
Andy-H Posted May 24, 2009 Share Posted May 24, 2009 Do you have ANY code so far? Do you know how to connect/query the database? Link to comment https://forums.phpfreaks.com/topic/159442-retrieving-information-from-a-form/#findComment-841073 Share on other sites More sharing options...
sprint10s Posted May 24, 2009 Author Share Posted May 24, 2009 yes i actually allready have my database file seperate in a include statement All ready have the html form which is a one row table where the user selects the company in the drop down list with a submit button but thats it Link to comment https://forums.phpfreaks.com/topic/159442-retrieving-information-from-a-form/#findComment-841075 Share on other sites More sharing options...
sprint10s Posted May 24, 2009 Author Share Posted May 24, 2009 I got the query i want ran for the search but i don't know how to specify the specific customer that hte user selected. below is the query SELECT company.Company_Name, company_info.Con_Phone_One, company.Address, company_info.Email_Con_One, company_info.Email_Con_Two, company_info.Email_Con_Three, company_info.Con_Phone_Two, company_info.Con_Phone_Three, company_info.User_Name, company_info.Ci_Password, company.Company_ID FROM company_info, company WHERE company.Company_ID =company_info.Company_ID Link to comment https://forums.phpfreaks.com/topic/159442-retrieving-information-from-a-form/#findComment-841080 Share on other sites More sharing options...
Andy-H Posted May 24, 2009 Share Posted May 24, 2009 <?php require_once "db.php"; if ( !isSet($_POST['submit']) ) { $qry = "SELECT Company_ID, Company_Name FROM company ORDER BY Company_ID DESC"; $res = mysql_query($qry)or trigger_error("MySQL ERROR: " . mysql_error()); ?> <form method="post" action=""> <select name="company"> <option value="">.......</option> <?php while ($row = mysql_fetch_row($res)) { echo " <option value=" . $row[0] . ">" . $row[1] . "</option>"; } echo " </select> </form>"; }else{ $ID = (int)$_POST['company']; $qry = "SELECT c.Company_Name, info.Con_Phone_One, " . "c.Address, info.Email_Con_One, info.Email_Con_Two, info.Email_Con_Three, " . "info.Con_Phone_Two, info.Con_Phone_Three, info.User_Name, " . "info.Ci_Password, c.Company_ID " . "FROM company AS c INNER JOIN company_info AS info USING(Company_ID) ". "WHERE c.Company_ID = $ID LIMIT 1"; $res = mysql_query($qry)or trigger_error("MySQL ERROR: " . mysql_error()); $ass = mysql_fetch_assoc($res); echo 'Company Name: ' . $ass['Company_Name'] . '<br >'; //etc... } That OK? Link to comment https://forums.phpfreaks.com/topic/159442-retrieving-information-from-a-form/#findComment-841095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.