Hi Guys,
Have a problem with a dropdown, which takes data from one table in MySQL database called ‘uploads’ and saves it in another called ‘news’ when I select it from the dropdown and hit submit:
Here’s all the code:
Now even though the dropdown does save the data selected from the dropdown table ‘uploads’ into the news table I still have two problems:
1) With the dropdown it has a blank space in between each value (see screenshot below)
2) As you will see the same page also GET’s the data from the MySQL database so I can edit it, so how do I get the dropdown to see that if I want to GET and edit for a particular record it shows the value I saved in my ‘news’ table for that record in the dropdown? As when I currently GET the dropdown, just displays blank.
Many Thanks
Cbo
Have a problem with a dropdown, which takes data from one table in MySQL database called ‘uploads’ and saves it in another called ‘news’ when I select it from the dropdown and hit submit:
Here’s all the code:
Code:
<?php
// login stuff
include("../something.php");
include("../somethingelse.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 picturemenuchoice='$picture' 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";
}
?>
<html>
<head>
<title>Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../ssheet.css">
</head>
<body>
<div align="center">
<form name="form1" method="post" action="">
<table width="100%" align="center" cellpadding="1" cellspacing="1">
<tr bgcolor="#CC0000">
<td colspan="3"><span class="yellow_bold">ADD NEWS:</span> <span class="white_bold">Please
Add Full Details</span></td>
</tr>
<tr>
<td colspan="3">
<p> </p>
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3" bgcolor="#FFFF00"><?php echo $msg?></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="3" valign="top">
<select name="picturemenuchoice">
<option value="" selected>select an image...</option>
<?php
$query = mysql_query("SELECT * FROM `uploads`");
while($picture = mysql_fetch_assoc($query)){
?>
<?php echo $_POST['picturemenuchoice']; ?> <? } ?></option>
<option value="<?php echo $picture['url']; ?>"><?php
echo $picture['name']; ?></option>
<?php
}
?>
</select>
<p align="right"><br>
<input type="submit" name="Submit" value="Submit" class="button">
<input type="reset" name="Reset" value="Reset" class="button">
</p>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Now even though the dropdown does save the data selected from the dropdown table ‘uploads’ into the news table I still have two problems:
1) With the dropdown it has a blank space in between each value (see screenshot below)

2) As you will see the same page also GET’s the data from the MySQL database so I can edit it, so how do I get the dropdown to see that if I want to GET and edit for a particular record it shows the value I saved in my ‘news’ table for that record in the dropdown? As when I currently GET the dropdown, just displays blank.
Many Thanks
Cbo