...

View Full Version : how to get rec id and Use header() to open new page and pass rec id



musher
08-27-2006, 06:45 AM
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?


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/showthread.php?t=89172&highlight=previous+page

musher
08-27-2006, 07:23 AM
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


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");
}

Fumigator
08-27-2006, 11:58 AM
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().



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum