Pulling data from a database to be emailed via PHP form
Posted: Thu Apr 15, 2004 7:37 am
Hi,
I'm very new to PHP and I wonder if anyone could help. I've created an online form which emails the results to me. It is all working fine apart from one field - a drop down menu of company names which gets its contents from a database (called tblCompanies). The field appears ok on screen, the company names are shown, but when the results are send in an email the company name (companyname) is replaced by the id number of the company (companyid).
The code for the drop down menu part of the form is here:
<select name="company" id="company" >
<option value="0">-- Select company from list --</option>
<?
// Select existing companies from the Companies table and populate option list
$query = "select * from tblCompanies GROUP by companyname order by companyname";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<option value=".$row["companyid"].">".$row["companyname"]."</option><br>";}
?>
</select>
and the line for emailing the selected company name is here:
$mesg .= "Company Applied to: $_POST[company]\n";
I would like it to be able to email the companyname to me, rather than the companyid, from the tblCompanies database.
Could anyone help me?
Many thanks for any help.
Rach
I'm very new to PHP and I wonder if anyone could help. I've created an online form which emails the results to me. It is all working fine apart from one field - a drop down menu of company names which gets its contents from a database (called tblCompanies). The field appears ok on screen, the company names are shown, but when the results are send in an email the company name (companyname) is replaced by the id number of the company (companyid).
The code for the drop down menu part of the form is here:
<select name="company" id="company" >
<option value="0">-- Select company from list --</option>
<?
// Select existing companies from the Companies table and populate option list
$query = "select * from tblCompanies GROUP by companyname order by companyname";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<option value=".$row["companyid"].">".$row["companyname"]."</option><br>";}
?>
</select>
and the line for emailing the selected company name is here:
$mesg .= "Company Applied to: $_POST[company]\n";
I would like it to be able to email the companyname to me, rather than the companyid, from the tblCompanies database.
Could anyone help me?
Many thanks for any help.
Rach