SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: Get problem

  1. #1
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get problem

    Hi Guys,

    Very quick one about get.

    Say I call the page:

    http://www.dsydsyweewewdudsudisididi...hp?story_id=12

    I then have a form that prints out an image where the story_id (in my cms_stories table) = story_id in my cms_pictures table:

    PHP Code:
    <?php 
    $story_id 
    = (int)$_GET['story_id']; 
    $SQL "select thumb_name,pic_id from cms_pictures where story_id = $story_id"
    $result mysql_query($SQL) OR die(mysql_error()); 
    $row mysql_fetch_row($result);        
    if (
    strlen($row['0']) > 0) { 
      echo 
    '<img src="../pictures/big/'$row['0'] .'">'
    } else { 
      echo 
    '<img src="../live_site/images/main_story.jpg">'
    }  
    echo 
    '<br><INPUT TYPE="checkbox" NAME="pic_id" VALUE="'.$row[1].'">'
    ?> <INPUT TYPE="hidden" NAME="form_submit" /> <INPUT TYPE="Submit" NAME="delete" VALUE="delete" />
    ?>
    Now when I press delete this image is deleted from my cms_pictures table:

    PHP Code:
    <?php 
    include("../**********");

    // if form has been submitted, run this: 

    if(isset($_POST['form_submit'])) 

    if(!empty(
    $_POST['delete'])) 

        
    $story_id = (int)$_POST['story_id']; 
        
    $pic_id = (int)$_POST['pic_id']; 
        
    mysql_query ("DELETE FROM cms_pictures WHERE pic_id = " $pic_id) OR die(mysql_error()); 
        
    header('Location: [url]http://www[/url]. dsydsyweewewdudsudisidididids.com/pictures/upload_edit.php?story_id='.$_GET['story_id']);  
        exit; 


    ?>
    However though when delete is clicked and I ask the page to go to:

    PHP Code:
     header('Location: http://www. dsydsyweewewdudsudisidididids.com /pictures/upload_edit.php?story_id='.$_GET['story_id']); 
    It won’t Get the story_id and just posts:

    http://www.dsydsyweewewdudsudisididi....php?story_id=

    Any ideas please as I thought $story_id = (int)$_GET['story_id']; would get the story_id

  2. #2
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the action attribute of the form set to? If it doesnt include the story_id as a GET variable then it won't be available to the page that processes the form.

  3. #3
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks. It is a POST from but I thought I could somehow still use GET in the form to get the story_id nomatter that i'm using post?

    Thanks

    Chris

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can't mix POST and GET. The HTTP protocol dictates that you can only send one type of request at a time. If your form action is POST, your browser will POST the data to the server.

    Put the story_id in a hidden field and get it from $_POST['story_id']

  5. #5
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use post method and try

  6. #6
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see thanks,

    So if I have a hidden field:
    PHP Code:
    <INPUT TYPE="hidden" NAME="story_id" VALUE="<?php echo $_GET['story_id'];?>" />
    and I have a href link so when I click on that link:

    PHP Code:
    <A HREF="http://www.??????????????????/stories/confirm_story.php?story_id=$story_id">Get the story id</A
    It goes to that page, but not with the story_id on the end? ie just to:

    http://www.??????????????????/stories/confirm_story.php??story_id=$story_id

    Many Thanks

  7. #7
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Location
    The Wirral, England
    Posts
    1,294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman
    You can't mix POST and GET. The HTTP protocol dictates that you can only send one type of request at a time. If your form action is POST, your browser will POST the data to the server.

    Put the story_id in a hidden field and get it from $_POST['story_id']
    Probably inadvisable but I've mixed them in the past by doing this:

    <form action="wherever.php?id=1" method="POST">
    form fields
    </form>

    Then you can access id from GET and the form fields from POST

    Alex
    "The proper function of man is to live - not to exist."
    Get a Free TomTom


  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It's a bad idea, and the data was still only POSTed. PHP let you pretend.

  9. #9
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <A HREF="http://www.??????????????????/stories/confirm_story.php?story_id=$story_id">Get the story id</A>

    do like this

    <A HREF="http://www.??????????????????/stories/confirm_story.php?story_id=<?=$story_id?>">Get the story id</A>

  10. #10
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but still cant get it to work:

    If i'm on this page:

    http://www.sloughactivate.co.uk/news...hp?story_id=12

    and on this page I have a hyperlink (as simplecode nicely posted) and a hidden field:

    <A HREF="http://www.sloughactivate.co.uk/stories/confirm_story.php?story_id=$story_id">Get the story id</A>

    <INPUT TYPE="hidden" NAME="story_id" VALUE="<?php echo $_GET['story_id'];?>" />

    Then surely this should pick up the story_id as 12? But it does not. Am I doing something very stooopid?

    Thanks

  11. #11
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you not working inside of a form?

    The hidden input field wont do anything if your not in the field.

    Also, like the guy said above, inside your link, you need to change $story_id to <?=$story_id?>
    BKerr

  12. #12
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7724
    Thanks, but still cant get it to work:

    If i'm on this page:

    http://www.sloughactivate.co.uk/news...hp?story_id=12

    and on this page I have a hyperlink (as simplecode nicely posted) and a hidden field:

    <A HREF="http://www.sloughactivate.co.uk/stories/confirm_story.php?story_id=$story_id">Get the story id</A>

    <INPUT TYPE="hidden" NAME="story_id" VALUE="<?php echo $_GET['story_id'];?>" />

    Then surely this should pick up the story_id as 12? But it does not. Am I doing something very stooopid?

    Thanks
    It's hard to help you when you keep switching the context of your questions. You've done it several times now. You can't be both clicking a link and submitting a form. A moment ago we were talking about a form being sent by POST. If that's the case, $_POST['story_id'] will be set after submitting a form containing that <input> above. If you click on a link with story_id in it, $_GET['story_id'] will be set on the page linked to.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •