Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-13-2005, 06:58 AM PHP dropdown issue?
Experienced Talker

Posts: 35
Trades: 0
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:


PHP 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($resultMYSQL_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>&nbsp;</p>
        </td>
      </tr>
      <tr> 
        <td colspan="3">&nbsp;</td>
      </tr>
      <tr> 
        <td colspan="3" bgcolor="#FFFF00"><?php echo $msg?></td>
      </tr>
      <tr> 
        <td colspan="3">&nbsp;</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
chrisb is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to PHP dropdown issue?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.08417 seconds with 12 queries