logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > General
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 09-06-2007, 04:43 PM   #1
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default PHP jump menu, cant send ID to next page.

Hi, After building a site for my camera club in ASP ( hosting restrictions ) they now want to make it more interactive. I have decided that I will rewrite the site in PHP.

I have changed the structure of the site so everything is now PHP pages, I've done all of DJs vids and have made a start on hand coding the gallery page.

I have hit my first hurdle as I cant get my jump menu to send an ID to the URL of the next page to display the chosen thumbnails. Once that is done I will need a thumbnail link to a further page to show the full image.

My code so far is as follows....

Code:
 
<?php
require_once("connections/connection.php"); // database connection
///////////////////////////////////////////
$photographerID  =   $_POST['photographerID'];
$firstname       =   $_POST['firstname'];
$lastname        =   $_POST['lastname'];
///////////////////////////////////////////
///////////////////////////////////////////
$query              =   sprintf("SELECT * FROM photographers");
$result             =   @mysql_query($query);
$photographerlist   =   @mysql_fetch_array($result);
///////////////////////////////////////////
?>
and the form is......

Code:
 
<form id="menu"
               method="post" action="gallery_detail.php?photographerID=<?php echo $photographerlist['photographerID']; ?>">
      <div align="right">
                <select name="menu"  class="photographerlist" onChange="document.forms[0].submit()">
    <option value="">Please choose a photographer</option>
 <?php do {  ?>
 <option value="<?php echo $photographerlist['photographerID']; ?>"><?php echo $photographerlist['firstname']; ?> <?php echo $photographerlist['lastname']; ?></option>
    <?php  }while ($photographerlist = mysql_fetch_array($result));  ?>
                </select>        
              </div>
            </form>
If anyone could point me in the right direction that would be great. I want to master PHP as I have more sites to build in the future. Thanks.

Oh! A future question I need answering too is how to get my MySQL database to the server. I've used Access before and just uploaded the file. I use EMS now so how do you go about going live?

Thanks again all, regards

Paul
tux is offline   Reply With Quote
Old 09-06-2007, 04:50 PM   #2
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

Oh!... The script does send the ID to the URL but only the first one it finds in the DB. Not sure if this helps.
tux is offline   Reply With Quote
Old 09-07-2007, 08:18 AM   #3
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

ok i can see what your doing here but your logic is wrong

first in your form just pass the form back to its self by setting the action to the page your on and catch the value of the dropdown in a $_POST

set the $_POST value to a $variable and do a...

PHP Code:
header("redirect:gallery_detail.php?photographerID=$variable");
exit; 
make sure to wrap the header in an IF to check that the $variable contains something because thats how you would know the form was submitted
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 09-07-2007, 08:51 AM   #4
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

Thanks David, at work now but will give it a go in my break as have my laptop with me. Could you give some thought to how the thumbs will be displayed on the detail page. Should I send the image ID as a variable too. If so how do I associate the two as they are in different tables. Both tables have the photographer ID.
tux is offline   Reply With Quote
Old 09-07-2007, 09:27 AM   #5
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

Ok, I've added....

Code:
 
$menu = $_POST['menu'];
...to the variables and the header with the IF....

Code:
 
if ($menu) {
header("redirect:gallery_detail.php?photographerID=$menu");
exit;
}
...above the closing php tag. I changed the action to..

Code:
 
"<php $SERVER['PHP_SELF']; ?>"
I know I have something wrong as the page loads but when I select from the drop down the page reloads with just white space????

What have I missed?

PS: Cant send code from laptop as using works internet connection for forum.
tux is offline   Reply With Quote
Old 09-07-2007, 10:34 AM   #6
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

will need to see all your code
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 09-07-2007, 10:46 AM   #7
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

Okay, have to wait til I get home. I'll have a play in my lunch break and see if I can suss it myself. I'll post again when I get home with the code. Thanks.
tux is offline   Reply With Quote
Old 09-07-2007, 04:38 PM   #8
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

No joy at lunch so here is the code....

PHP Code:
<?php
require_once("connections/connection.php"); // database connection
///////////////////////////////////////////
if ($menu){
header("redirect:gallery_detail.php?photographerID=$menu");
}
///////////////////////////////////////////
///////////////////////////////////////////
$photographerID  =   $_POST['photographerID'];
$firstname       =   $_POST['firstname'];
$lastname        =   $_POST['lastname'];
$menu            =   $_POST['menu'];
///////////////////////////////////////////
///////////////////////////////////////////
$query              =   sprintf("SELECT * FROM photographers");
$result             =   @mysql_query($query);
$photographerlist   =   @mysql_fetch_array($result);
///////////////////////////////////////////
?>
and the form....

PHP Code:
 <form id="menu" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
       <select name="menu"  class="photographerlist" onChange="document.forms[0].submit()">
    <option value="">Please choose a photographer</option>
 <?php do {  ?>
 <option value="<?php echo $photographerlist['photographerID']; ?>"><?php echo $photographerlist['firstname']; ?> <?php echo $photographerlist['lastname']; ?></option>
    <?php  }while ($photographerlist mysql_fetch_array($result));  ?>
                </select>        
              </form>
The page just reloads when a selection is made from the list and does not redirect to the detail page.
tux is offline   Reply With Quote
Old 09-08-2007, 08:00 AM   #9
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

ok

question...

how can you resolve your header redirect variable when your $_POST / $menu is written after the header is called????

you have to understand the logic when writing PHP.

you have this...

PHP Code:
if ($menu){
header("redirect:gallery_detail.php?photographerID=$menu");

then after you have this...

PHP Code:
$menu $_POST['menu']; 
so your header function can never resolve the $menu variable as the variable is called after.

also you should always add an exit after your header as this will stop any other code running and again is best practice

PHP Code:
if ($menu){
header("redirect:gallery_detail.php?photographerID=$menu");
exit;

__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 09-08-2007, 08:18 AM   #10
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

I had noticed that I'd missed off the exit after I posted last.

I have moved the header code to the bottom and now when a selection is made the page reloads to itself but is just white and does not redirect to the detail page??

What is it I'm missing here.
tux is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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

Forum Jump


All times are GMT. The time now is 06:41 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com