Hi,
I am not too good on php and MYSQL and I am currently struggeling with populating a form on my website based on a selection chosen by the user from a drop down menu.
The drop down menu is dynamic with its values populated from a database. Below the menu is a form that has two functions which are:
1. It allows the user to write information to the database.
2. Allows the user to view and edit records from the database.
The data held in the drop down menu is the the title of the record, and when a new record is added to the database it automaticalty gets added to the menu. The problem comes with when the user choses an option from the menu as the form needs to display the corrasponding data but I dont know how to do this. For example, if JAN is chosen from menu the form should be repopulated with the data input by the user for that record.
So far the code I have is:
<?php
session_start();
// Database Connection
mysql_connect("www.numyspace.co.uk", "unn_s013370", "********")or die("connect");
mysql_select_db("unn_s013370")or die ("cannot select DB");
if (isset($_SESSION["Student_ID"])) {
$username = $_SESSION['Student_ID'];
echo "Log in as ".$username;
} else {
// not logged in so redirect
header("location: LOGIN2.html");
exit;
}
if (isset($_SESSION["Student_ID"])) {
$First_Name = $_SESSION['Student_ID'];
}
if (isset($_SESSION["Password"])) {
$Gender = $_SESSION['Password'];
}
//populate dropdown mene with users recorded logs
//select data from database based on Student ID
$sql="SELECT LogMonth, LogYear FROM Student_MLog WHERE Student_ID='$username'";
//assign query results to sql variable
$result=mysql_query($sql);
//create drop down menue on screen
echo "<select name='logdropdown' >";
while ($row=mysql_fetch_array($result)) {
$LogMonth=$row["LogMonth"];
$LogYear=$row["LogYear"];
//display db data in menu
echo "<option>$LogMonth<option/>";
}
echo "<select/>";
?>
... and the form code is...
<!--activity field + log title-->
<div class = "activity_field">
<form action="activity.php" method="post">
<label>Log Month
<input type="text" name="logmonth" size="25">
</label>
<label>Log Year
<input type="text" name="logyear" size="25">
</label>
<br/>
<label>Activities:
<textarea cols="50" rows="13" name="activity"></textarea>
</label> <br />
<input type="image" src="button_SAVE.png" name="image" width="170" height="100">
</form>
</div>
Any help would be greatly appriacted as I have benn looking into this for nearly a week but with no luck as of yet.