Hi,
I'm having a problem with the header:location. The code below is to insert values into an articles table and a artsections table.
Once the article has been inserted I get the id using
mysql_insert_id()
After all the inserting has been done I want to redirect to the same page passing the id across. To do this i'm using
header('Location: articles.php?id='.$latestID.''); The problem is that if i have
?id='.$latestID.' the article does not insert and the querystring is not passed across when the redirect happens.
if i change the location to a page other than itself it works as it should, the article gets inserted and the id is passed across.
PHP Code:
$sqlInsert = "INSERT INTO articles (art_title, art_approved, art_image1, art_image2, art_image3, art_image4, art_date, art_headline, art_author, art_order, art_comments, art_rss, art_archived, art_document, art_link, art_linktarget, art_parent, art_publishdate, art_misc1, art_misc2, art_misc3) VALUES ('". $artTitle ."', '". $artApproved."', '". $artImage1."', '". $artImage2."', '". $artImage3."', '". $artImage4."', '". $artDateCreated."', '". $artHeadline ."', '". $artAuthor."', '". $artOrder."', '". $artComments."', '". $artRSS."', '". $artArchived."', '". $artDocument."', '". $artLink."', '". $artLinktarget."', '". $artParent."', '". $artPublishdate."', '". $artMisc1."', '". $artMisc2."', '". $artMisc3."')";
mysql_query($sqlInsert);
$latestID = mysql_insert_id();
//Array to get the section ids from the multiple select list and insert them into the artsections table
if(isset($_POST['txtSection'])){
$srtSection = $_POST['txtSection'];
if(is_array($srtSection)){
while (list($key, $val) = each ($srtSection)){
$sqlArtsection = "INSERT INTO artsections (as_section, as_article) VALUES ($val,$latestID)";
mysql_query($sqlArtsection);
}
}
}
//header('Location: articles.php?id='.$latestID.'');
header("location: ".$_SERVER['PHP_SELF']."");
I hope someone can point me in the right direction to help me solve my problem.
Wayne.