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
Dropdown Problems in PHP and MySQL?
Old 06-09-2005, 04:44 AM Dropdown Problems in PHP and MySQL?
Experienced Talker

Posts: 35
Trades: 0
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 in a variable called 'piicture' when I hit submit.

PHP 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:

PHP 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($resultMYSQL_BOTH);
    
$picture $row['picturemenuchoice'];
}

if(
mysql_error())
{
echo 
mysql_error() ."<br>\n";
}

?>
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
chrisb is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-09-2005, 08:07 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Well... have you firstly checked to see if the database is being added to?? Also, why in the php have you got a $_POST and $_GET working together?? Surely that's not possible, unless in the HTML you have <FORM ACTION="www.server.com/?var=value" METHOD="POST"> ??

The last bit where u talk about the drop down still being on "select an image..." it would be that all the time becase its the first data in the drop down and you have "SELECTED" in the option bracket.

We generally advise u posting the whole PHP script
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 06-09-2005, 10:34 AM
Experienced Talker

Posts: 35
Trades: 0
Hi,

Thanks for the reply. Points noted!

Reason I have POST and GET working together is because when I POST the data I can then use the same form to GET the data and modify it for the database.

As for the dropdown, where it returns to 'select an image' when you hit submit, where do I change that so it stays on what I selected - I don't understand?

Many Thanks

chrisb is offline
Reply With Quote
View Public Profile
 
Old 06-09-2005, 11:05 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Ok, since i'm not too sure how ur processing the PHP and stuff for the drop down, i'll use one of my own examples. This is taken from a client in a band (www.festerband.com) who can basically control their content using my CMS. The below code prints out in a drop down box for the year in the date of a future gig they wish to post on their Gigs page, but also allows them to edit the existing gigs they have posted, so we need to be able to recall the date into the drop down boxes on the page:

PHP Code:
<SELECT SIZE=CLASS=forminput NAME=gigs_listing_year>');

// 2005 is the current year!
$i = '
2005';
// Let'
s allow them to book gigs 3 years in advanceso add 3 to 2005 (=2008)
$j $i 3;

        
// So while $i is less than or equal to $j
    
while ($i <= $j) {

        
// Be it selected or not, we have to print the basic HTML
        
echo('<OPTION VALUE=' $i ' ');
        
/* The next if statement uses a variable which has been
            taken from the SQL DB where the gigs are stored, so if
            $i (which gets increased each loop) equals what is in the 
            database... */
        
if ($gigs_listing_year == $i) {
            echo(
'SELECTED');
        }

         
// This bits obvious
        
echo('>' $i '</option>
        '
);

         
// We MUST increase $i, or we have a neverending loop!
        
$i++;
            
    }

echo(
'
</SELECT> 
Hope that explains something?? You need to get the $gig_listing_year (change the name as appropriate) from somewhere, be it a database or from the form that has just been processed, or just from a query string - that bits up to u to figure!

Hope this helps??
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Dropdown Problems in PHP and MySQL?
 

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.14155 seconds with 12 queries