hello,
essentially i have two pages one for a user to submit out a form and another which is a confirmation form which then enters the data to populate my database. i can only use php embedded into html, I have managed to create a dropdown menu using an array and loop now i am struggling to get any response from it to connect with my confirmation page and enter data to my database thank you for your help. below is the form registration code
<?php
include ("db.php");
$pagename="Add Employee";
?>
<?php $coCodes = array('10', '20', '30', '40');
echo "<select name ='form_companycode' >";
echo"<option value = ''></option>";
foreach($coCodes as $x)
{
echo"<option value ='$x'>$x</option>";
}
echo"</select>";
?>
//for ($x=0; $x<sizeof($coCodes); $x++)
//echo '<option>'. $coCodes[$x] . '</option>';
<title></title>;
<h2>Add employee below</h2>";
<body>
<?php.date('d F Y H:i:s');?>
<hr>Fill the form below to add a new Employee;</hr>
<?php
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"<tr><td><input type=submit value='Add Employee'></td>";
echo"<td><input type=reset value='Clear Form'></td></tr>";
echo"</table>";
echo"</form>" ;
?>
this is the confirmation code
<?php
include("db.php");
$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>";
$employeeid=$_POST['form_employeeid'];
$fullname=$_POST['form_fullname'];
$position=$_POST['form_position'];
$email=$_POST['form_email'];
$companycode=$_POST['$x'];
//check if any of the mandatory fields were not filled in
if($_SERVER['REQUEST_METHOD'] === 'POST'){ // Check for form submission
var_dump($_POST); // Temporary to check form input is as expected
exit; // and stop there for now
}
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!";
}
else
{
//if an optional field was not filled in then write SQL query without the column
{
$addEmployeeSQL=
"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
else
{
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>";
?>
</body>";