Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder musher's Avatar
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to get rec id and Use header() to open new page and pass rec id

    I have a page that is used add/mod/delete records I have couple of question.

    1. After the record is inserted I would like to open page_add.php and pass the record id (there is an auto_increment field in the table called ID) to the new page "page_add.php". I was thinking of using header() to open the new page and passing the id as parameter (i.e. page_add.php?rec_id=what ever) is there a better way to do this?
    2. how would I get the record id after I store the new record?
    3. Also not sure how to write header() with a variable in it?

    PHP Code:
      if ((isset($_POST["REC_insert"])) && ($_errLvl == "N")) {
        
    $sql sprintf("INSERT INTO menu (menu_title,display_order,link_url) VALUES (%s, %s, %s)",
          
    GetSQLValueString($_POST['menu_title'], "text"),
          
    GetSQLValueString($_POST['display_order'], "text"),
          
    GetSQLValueString($_POST['link_url'], "text"));
        
    $result mysql_query($sql);
        
    $var_message "New " .$var_section_name" Record has been Added.";

    ** 
    need to get ID and store to variable $var_rec_id **

        
    header("Location: page_add.php?rec_id=");
      } 

    UPDATE: ok found the answer to question 2 looking for somthing else --- fyi for any one that needs check out http://www.codingforums.com/showthre...=previous+page
    Last edited by musher; 08-27-2006 at 08:08 AM.
    Thanks
    Jim M

    "Lord, help me to become the person my dog thinks I am" - Dawn Ewing
    "If you must know. Yes, I do enjoy running after the dog sled when I fall off" - Me

    www.huskyzone.com -- Woodland Siberians

  • #2
    Regular Coder musher's Avatar
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok I got something working just want to know if there is a better way to do it or if this is an ok pratice

    PHP Code:
      if ((isset($_POST["REC_insert"])) && ($_errLvl == "N")) {
        
    $sql sprintf("INSERT INTO menu (menu_title,display_order,link_url) VALUES (%s, %s, %s)",
          
    GetSQLValueString($_POST['menu_title'], "text"),
          
    GetSQLValueString($_POST['display_order'], "text"),
          
    GetSQLValueString($_POST['link_url'], "text"));
        
    $result mysql_query($sql);
        
    $var_message "New " .$var_section_name" Record has been Added.";
        
    $_SESSION['menu_recID'] = mysql_insert_id();
        
    header("Location: page_add.php");
      } 
    Thanks
    Jim M

    "Lord, help me to become the person my dog thinks I am" - Dawn Ewing
    "If you must know. Yes, I do enjoy running after the dog sled when I fall off" - Me

    www.huskyzone.com -- Woodland Siberians

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Looks OK to me, since that's just how I do it too

    I usually put a call to ob_start() up top to make sure nothing gets output before I call header().


  •  

    Posting Permissions

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