Jump to content

need help with populating a drop down box to select employee ID and submit


kat35601

Recommended Posts

not sure how to do this I have the sql and a attempt at pulling the list but it fails with 

Notice: Undefined variable: select in line 22 which is the 

$select.='<option value="'.$row['lmeEmployeeID'].'">'.$row['lmeEmployeeName'].'</option>';

and then hot to submit it to the other page???? like at the bottom of the below code.

<html>
<head>
<title>Employee</title>
</head>
<body>
<h1>Employee IDe</h1>
<?php
$connect =odbc_connect("removed");
if(!$connect) {
	exit("Connection Failed: " . $connect);
}

$sql="
select lmeEmployeeName, lmeEmployeeID from  m1_kf.dbo.Employees where lmeTerminationDate IS NULL
";
$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
while ($row = odbc_fetch_array($result))
{
      $select.='<option value="'.$row['lmeEmployeeID'].'">'.$row['lmeEmployeeName'].'</option>';
  }

$select.='</select>';



?>
<form method="post" action="employee.php">
<input type="text" name="salesman">
<input type="submit"> 
</form> 
</body>
</html>
Link to comment
Share on other sites

Example:

<?php
    $sql  = "SELECT id, name FROM table";
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetchAll();
?>
<form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post"> 
    <select name="id">
    <?php foreach ($result as $row) :?>
    <option value="<?= $row['id']; ?>"><?= $row['name']; ?></option>
    <?php endforeach; ?>
    </select>
    <button name="submit" class="btn btn-primary">Submit</button>

</form>
Edited by benanamen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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