How to link PHP drop down list to submit confirmation and populate sql table

Hi, i have managed to create a drop list but i cannot get it to submit towards my confirmation page nor insert the data into my sql. Thank you

this is my add employee page where the user enters details

include ("db.php");
$pagename="Add Employee";
echo "<title>".$pagename."</title>";
echo "<h2>".$pagename."</h2>";
echo "<body>";
echo "<hr><b>".date('d F Y H:i:s')."</b>";
echo "<hr>Fill the form below to add a new Employee";

//create a html form to capture user input
echo "<form method=post action=getemployee.php>" ;
echo "<table border=0 cellpadding=10>";
echo "<tr><td>*Employee ID </td>";
echo "<td><input type=text name=form_employeeid size=35></td></tr>";
echo "<tr><td>*Full Name </td>";
echo "<td><input type=text name=form_fullname size=35></td></tr>";
echo "<tr><td>*Position </td>";
echo "<td><input type=text name=form_position size=35></td></tr>";
echo "<tr><td>*Email </td>";
echo "<td><input type=text name=form_email size=35></td></tr>";
echo "<tr><td>*Company Code </td>";
echo "<td><name=form_companycode size=35></td></tr>";
echo "<select>";
echo "<option value='1'>10</option>";
echo "<option value='2'>20</option>";
echo "<option value='3'>30</option>";
echo "<option value='4'>40</option>";
if ('form_companycode'=='1') echo '10'; 
else if ('form_companycode'=='2') echo '20';
else if ('$form_companycode'=='3') echo '30';
else if ('$form_companycode'== '4') echo '40';    
echo "</select> ";

//$companycode = array('10', '20', '30', '40');
//echo '<select>';
//foreach($companycode as $companycode => $companycode){
//echo '<option value=' . $companycode . '>' . $companycode . '</option>';
//echo '</select>';

echo "<tr><td><input type=submit value='Add Employee'></td>";
echo "<td><input type=reset value='Clear Form'></td></tr>";
echo "</table>";
echo "</form>" ;

echo "</body>";

this is my confirmation page

$pagename="New Employee Confirmation";
echo "<title>".$pagename."</title>";
echo "<h2>".$pagename."</h2>";
echo "<body>";
echo "<hr><b>".date('d F Y H:i:s')."</b>";


//check if any of the mandatory fields were not filled in
if (empty($employeeid) or empty($fullname) or empty($position) or empty($email) or empty($companycode))
	echo "<p>Please ensure all fields with a * are filled in!";
	//if an optional field was not filled in then write SQL query without the column
		"insert into 
		w1668315_Employee (w1668315_empID, w1668315_empFullName, w1668315_empPosition, w1668315_empEmail, w1668315_compCode)
		values (".$employeeid.", '".$fullname."','".$position."','".$email."',".$companycode.")";
	//if optional was filled in, include column in SQL query
	//run SQL query
	$exeaddEmployeeSQL=mysqli_query($conn, $addEmployeeSQL);
	if (mysqli_errno($conn)==0)
		echo "<p>A new Employee has been added successfully";
		echo "<p>Added Employee id: ".$employeeid;
		echo "<br>Added Full Name: ".$fullname;
		echo "<br>Added Position: ".$position;
		echo "<br>Added Email: ".$email;
		echo "<br>Added Company Code: ".$companycode;
	//else check individual error codes and display appropriate message
		echo "<p>There is an error with the Employee you entered.";
		//error code for breach of PK or unique constraint
		if (mysqli_errno($conn)==1062)
			echo "<br>The value entered for the new Employee id is not valid as it already exists.";			
		//error code for inserting character that is problematic for SQL query
		if (mysqli_errno($conn)==1064)
			echo "<br>Values entered for the Employee details are not valid.";			

echo "</body>";

I would suggest you first start with cleaning up what you have. Do not echo 100% HTML. Make this a single page, HTML at the bottom, form processing code at the top. Do not use tables for layout. Use CSS instead. You are also missing a couple dollar signs from your variables. Create an errors array and make each form error it’s own error instead of the group error you have done.

thanks for the reply but unfortunately i must use php embedded in html to create the form

Yeah, no you don’t. Maybe the select but hard to tell at the moment.

Also, NEVER EVER put variables in your query. You need to use prepared statements. I would also highly recommend you use PDO. Additionally, do not create variables for nothing. You will also need to trim the post array before your error checks as a space is considered not empty.

this is for my assignment to gain extra marks i must essentially create a drop down where the user selects their company code ranging from 10-40. I already completed this using html on top then php at bottom but the lectuter said he wants embedded php into html now i am confused there is no possible way to achieve that surely? unless i am going crazy everyone online has created forms with html on top then php bottom as you have said

Your instructor needs to be fired. He is teaching you wrong. We see that often on the forums. I would say do it correctly and then tell the instructor to go back to school when you hand it in.

so should i just submit my previous code with html on top and php bottom it worked fine and filled in my database without errors?

Post the other code and we can review it.

ok it will take a while since i overwrit it thanks.

this general html code along with the linked sql query code on my confirmation page works fine and populates my sql table

OP, pictures are for hanging on the wall. Post the actual code.

it always come out wrong

form method=post action=getemployee.php>

table border=0 cellpadding=10>
tr><td>*Employee ID </td>
td>input type=text name='form_employeeid' size=35></td></tr>
tr><td>*Full Name </td>
td>input type=text name='form_fullname' size=35></td></tr>
tr>td>*Position /td>
td>input type=text name='form_position' size=35></td></tr>
tr>td>*Email </td>
td>input type=text name='form_email' size=35></td></tr>
tr>td>*Company Code </td>
div id = "move"> 
select name='form_companycode'>
option value = "10">10</option>
option value = "20">20</option>
option value = "30">30</option>
option value = "40">40</option>
tr>td>input type=submit value='Add Employee'>/td>
td>input type=reset value='Clear Form'>/td>/tr>
#move {
	bottom: 500px;

include ("db.php");
$pagename="Add Employee";
echo "<title>".$pagename."</title>";
echo "h2>".$pagename."</h2>";
echo "body>";
echo "hr><b>".date('d F Y H:i:s')."</b>";
echo "hr>Fill the form below to add a new Employee";

i had to obviously delete a bit

i am worried that i will not get any marks because it seems to simple but tbh they said they dont care if u add css you wont gain extra marks as long as user data can be entered and you have a confirmation landing page alongside your table being populated.

this is my first time using php and i do not simply understand how one can be expected to make a form with a drop down by embedding php into html? unless it is possible. I appreciate any clarification many thanks.

What are the EXACT requirements? Also, post your current DB structure.

we have a customer table which you fill in randomly and the end user fills in the employee table

create table w1668315_Company (
w1668315_compCode int(10),
w1668315_compDescription varchar(50) unique not null,
w1668315_compName varchar(50) not null, 
constraint c_cde_pk Primary Key (w1668315_compCode)

create table w1668315_Employee (
w1668315_empID int(10),
w1668315_empFullName varchar(50) not null,
w1668315_empPosition int(25) not null,
w1668315_empEmail varchar(50) not null,
w1668315_compCode int(10) not null unique,
constraint e_eid_pk Primary Key (w1668315_empID),
constraint c_cde_fk Foreign Key (w1668315_compCode)references w1668315_Company(w1668315_compCode)

this should be the end result but surely that cannot be produced with php only with html embedded eg echo"tr>td>full name etc…