Jump to content

retrieving information from a form


sprint10s

Recommended Posts

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

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

 


<?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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.