Hi Guys,
I am trying to select some data taken from one table called 'uploads' in MySQL database that is held in a dropdown menu and place that data in another table called 'news' in the MySQL database when I hit submit.
Now this works a treat, but when I submit the data the name of the image does NOT stay on the name of the image I have just chosen, it justs goes back to 'select an image', and also it does not not show the image name I have chosen when I go in and edit the selected dropdown item and again shows 'select an image'.
Now I have this code:
I am trying to select some data taken from one table called 'uploads' in MySQL database that is held in a dropdown menu and place that data in another table called 'news' in the MySQL database when I hit submit.
Code:
<select name="picturemenuchoice">
<option value="" selected>select an image...</option>
<?php
$query = mysql_query("SELECT * FROM `uploads`");
while($picture = mysql_fetch_assoc($query)){
?>
<option value="<?php echo $picture['url']; ?>"><?php
echo $picture['name']; ?></option>
<?php
}
?>
</select>
Now this works a treat, but when I submit the data the name of the image does NOT stay on the name of the image I have just chosen, it justs goes back to 'select an image', and also it does not not show the image name I have chosen when I go in and edit the selected dropdown item and again shows 'select an image'.
Now I have this code:
Code:
<?php
// login stuff
include("nameoffile.php");
include("ddwsff.php");
checklogin();
$picture = "";
if(isset($_POST['Submit']))
{
$picture = $_POST['picturemenuchoice'];
if(!isset($_GET['newsid']))
{
$result = mysql_query("Insert into news(picture) values('$picture')");
$msg = "New record is saved";
}
else
{
$result = mysql_query("Update news set picture='$picturemenuchoice' where newsid=".$_GET['newsid']);
$msg = "News Record is updated";
}
}
if(isset($_GET['newsid']))
{
$result = mysql_query("Select * From news where newsid=".$_GET['newsid'],$link);
$row = mysql_fetch_array($result, MYSQL_BOTH);
$picture = $row['picturemenuchoice'];
}
if(mysql_error())
{
echo mysql_error() ."<br>\n";
}
?>
[code]
Which states what should happen when I submit. have I got it wrong anywhere when it saves so that instead of showing 'select an image' it will show the image name I have selected from the dropdown when I hit submit?
Many Many Thanks
CB