Forum Moderators: coopster
I would appreciate any tips or help to solve this problem. Thank you.
<?php
require('config.php');
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
or die('Could not connect to MySQL database. ' . mysql_error());
mysql_select_db(SQL_DB,$conn);
$duty = 'Select Title From Dropdown List, Then Press the Display Function button';
$id = 0;
// get duty from database, if a title has been selected
if (true == isset($_POST['showduty']))
{
$id = intval($_POST['sel_category']);
$sql = 'SELECT duty FROM title_duty WHERE id = ' . $id;
$result = mysql_query($sql);
if (false == $result)
{
echo 'Failed to execute ' . $sql . ' due to ' . mysql_error() . '<br />';
}
else
{
$duty = mysql_result($result, 0);
mysql_free_result($result);
}
}
// build list of titles for drop-down
$opt = '';
$sql = 'SELECT id, title FROM title_duty ORDER BY title ASC';
$result = mysql_query($sql);
if (false == $result)
{
echo ' Failed to execute ' . $sql . ' due to ' . mysql_errr() . '<br />';
}
else
{
$opt = '<select name="sel_category">';
while ($row = mysql_fetch_assoc($result))
{
$selected = ($id == $row['id'])? ' selected ' : '';
$opt .= '<option value="' . $row['id'] .'"' . $selected . '>' . $row['title'] . '</option>';
}
$opt .= '</select>';
mysql_free_result($result);
}
mysql_close();
?>
<html>
<head>
<title>Job Editor</title>
</head>
<body leftmargin='0'>
<form name="title_duty" method="post" action=" <?php echo $_SERVER['PHP_SELF'];?> ">
<table border='0' cellpadding='0' width='100%'>
<tr>
<td><b>Job Title</b></td></tr>
<tr><td height='30' valign='top'>
<?php echo $opt;?>
<br /></td></tr>
<tr>
<td><b>Essential Functions</b></td></tr>
<tr><td height='30' valign='top'>
<textarea" name="duty" rows="15" cols="140">
<?php echo $duty;?>
</textarea>
<br />
<input type="submit" name="showduty" value="Display Function" />
</td>
</tr>
</table>
</form>
</body>
</html>
Ok, a couple of things to note here. Firstly, this:
if (true == isset($_POST['showduty']))
Would that not be better as:
if (isset($_POST['showduty']))
Also if (false == $result) can be simply if ($result)
Also, your sql statement does not have the value between apostrophes, so I am assuming this is not returning any results:
$sql = 'SELECT duty FROM title_duty WHERE id = ' . $id;
Change that to:
$sql = "SELECT duty FROM title_duty WHERE id = '" . $id . "'";
See if that helps any for starters.
dc