kat35601 Posted September 8, 2016 Share Posted September 8, 2016 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> Quote Link to comment https://forums.phpfreaks.com/topic/302107-need-help-with-populating-a-drop-down-box-to-select-employee-id-and-submit/ Share on other sites More sharing options...
Barand Posted September 8, 2016 Share Posted September 8, 2016 (edited) Set $select='' before the while loop. You are attempting to append to a non-existant string. Edited September 8, 2016 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/302107-need-help-with-populating-a-drop-down-box-to-select-employee-id-and-submit/#findComment-1537189 Share on other sites More sharing options...
kat35601 Posted September 8, 2016 Author Share Posted September 8, 2016 That fixed the select error. How do I get the list in the submit box???? Quote Link to comment https://forums.phpfreaks.com/topic/302107-need-help-with-populating-a-drop-down-box-to-select-employee-id-and-submit/#findComment-1537190 Share on other sites More sharing options...
benanamen Posted September 8, 2016 Share Posted September 8, 2016 (edited) 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 September 8, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/302107-need-help-with-populating-a-drop-down-box-to-select-employee-id-and-submit/#findComment-1537191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.