Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
header("location: ".$_SERVER['PHP_SELF']."");
Old 06-04-2010, 05:15 AM header("location: ".$_SERVER['PHP_SELF']."");
Skilled Talker

Posts: 50
Trades: 0
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.

Last edited by HullBorn; 06-04-2010 at 05:18 AM..
HullBorn is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-04-2010, 08:50 AM Re: header("location: ".$_SERVER['PHP_SELF']."");
Super Talker

Posts: 139
Name: John Davis
Trades: 0
You have to check $latestID before Location stringcreation.
Also you have to use "Location" instead of "location".
__________________
»
Please login or register to view this content. Registration is FREE
- Interactive maps for websites
»
Please login or register to view this content. Registration is FREE
for web developers
MapMaster is offline
Reply With Quote
View Public Profile Visit MapMaster's homepage!
 
Old 06-04-2010, 03:05 PM Re: header("location: ".$_SERVER['PHP_SELF']."");
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Looking at your snippet of code, if you redirected to itself, then there will be a recurcive redirect because it would continue to insert a new row in the db for each load of the page.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to header("location: ".$_SERVER['PHP_SELF']."");
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25216 seconds with 12 queries