Help with PHP and MySQL

Hi Everyone,

I need some help with php and mysql. I have a database in mysql and a few tables (tables are: users and issues). Here is the layout of the tables.
users table columns: id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(45).
issues table columns: id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, issuedate DATE NOT NULL, summary VARCHAR(255) NOT NULL, userid INT NOT NULL.

Now, what I want to do is create a form so employees can submit issues. for the user’s part I want the users to be displayed using a select tag getting the user’s name from the users table. the employees will see the users that are available and pick one to assigned to that specific issue and when the form is submitted, I want the key for that user to be entered to match the users.id in the users table.

Please help!!! I have all the PHP books from learnable and site point but none of them explain how to work with select, checkbox, etc tags and submitting form to match id from another table.

Thank you in advanced for the help!!!

By “users” do you mean the support staff for a company? Are they all employees of the same company? What thing are the support staff offering support for, eg an IT system?

rcbdrummin helped me with this issue already its working fine. I’ll post the answer below. Again I want to say thank you to Robert D.

<?php
//PDO version
$host = “localhost”;
//MySQL Database user name.
$login = “”;
//Password for MySQL.
$dbpass = “”;
//MySQL Database name.
$dbname = “”;
$pdo = new PDO(“mysql:host=localhost;dbname=$dbname”, “$login”, “$dbpass”);

//Create users array
$Users = array();

//Sql
$sql =“SELECT id, name FROM users ORDER BY id ASC”;
//Prepare query
$query = $pdo->prepare($sql);
//Execute query
$query->execute();
//Use WHILE to loop through records and build array.
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$Users[$row[‘id’]] = $row[‘name’];
}
//Test result by printing array
//echo “<pre>”;
//print_r($Users);
//echo “</pre>”;
//////////////////////////////////

//Test POST by printing POST array
//echo “<pre>”;
//print_r($_POST);
//echo “</pre>”;
//Check for post
if(isset($_POST[‘submit’])):
if(empty($_POST[‘user_id’]) || empty($_POST[‘summary’])){
$error = “Please select name and add message”;
}else{
$issuedate = date(‘Y-m-d’);
$sqli = “INSERT INTO issues (issuedate, summary, userid)
VALUES(:issuedate, :summary, :userid)”;
$queryi = $db->prepare($sqli);
$queryi->bindParam(“:issuedate”, $issuedate);
$queryi->bindParam(“:summary”, $_POST[‘summary’]);
$queryi->bindParam(“:userid”, $_POST[‘user_id’]);
$queryi->execute();
}
endif;
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml” xml:lang=“en” lang=“en”>
<head>
<title></title>
</head>
<body>
<?php
if(isset($error)){ echo $error;}
?>
<form action=“” method=“post”>
<select name=“user_id” style=“width:200px;”>
<option value=“”> Select Name </option>
<?php
foreach($Users as $user_id => $name):
echo ‘<option value="’ . $user_id . ‘">’ . $name . ‘</option>’.“\r”;
endforeach;
?>
</select><br />
<textarea name=“summary” style=“width:200px;”></textarea><br />
<input type=“submit” name=“submit” value=“Submit” />
</form>
</body>
</html>