I have two tables. tbl_clients and tbl_projects. They both contain auto incremented primary key columns.
For adding new projects to tbl_projects, I use tbl_clients' clientname field to populate a dropdown menu on the new projects html form. The user chooses a client name from the menu, and the primary key of that client is inserted into tbl_projects for relational purposes.
Next, I have a php script which accepts this form data and inserts it into tbl_projects and then emails the data to a recipient. This is working well except for the client name.
Since what is being passed to the page is the primary key and not the client name, how do i translate the key into it's corresponding client name so i can use it as a variable for the subject line? I'm assuming some sort of query but I'm just not familiar enough with php to get it right. Is there a way to pass the client name from the previous page along with it's primary key?
//This is the php within the form that creates the client name/clientid menu
<?php
$query = "SELECT clientname , clientid FROM tbl_clients";
$result = mysql_query($query) or die(mysql_error());
$dropdown = "<select name='clientid' value='clientname' id='clientname'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n<option value='{$row}'>{$row}</option>";}
$dropdown .= "\r\n</select>";
echo $dropdown;
?>
//This is the script that inserts the data to mysql and emails it.
<?php
mysql_connect("xxx","xxx","xxx");
mysql_select_db("xxx");?>
<?php
$clientid=$_POST;
$project=$_POST;
$type=$_POST;
$target=$_POST ;
$priority=$_POST ;
$notes=$_POST;
$start=$_POST;
$status=$_POST;
$finish=$_POST;
$time=$_POST;
$perhour=$_POST;
$invoice=$_POST;
$sql="INSERT INTO tbl_projects (clientid , project , type , target , priority , notes , start , status , finish , time , perhour , invoice) VALUES ('$clientid' , '$project' , '$type' , '$target' , '$priority' , '$notes' , '$start' , '$status' , '$finish' , '$time' , '$perhour' , '$invoice')";
$result=mysql_query($sql);
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
$to = "xxx@xxx.com";
$from = "xxx@xxx.com";
$subject = "$clientname"; //< this is where i'm having the trouble
$message = "the birds.";
mail($to , $subject , $from , $message) ;
mysql_close();
?>