Redirection after script complete.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Redirection after script complete.

Post by synical21 »

Hello Experts.

I have a problem with redirection using php. Basically when a user clicks this button they are taken to "proofprocess.php" which is a series of MySQL calculations changing user values.

I want to queries to run then direct back to the page the user was last on. I done it like this

Code: Select all

 
<?
  
     
 $sql = "SELECT `proof`.*,
        `users`.*
   FROM `proof`,`users`,`fulldata`
  WHERE users.id = $id
    AND proof.userproof_id = $id
    AND proof.job_id = $_GET[jid]";
 $result = mysql_query($sql)
     or die('Invalid query: ' . $sql . ' - Error is ' . mysql_error());
     
     $sql = "UPDATE `users`,`proof`
    SET clickstatus = 1
  WHERE proof.userproof_id = $id
  AND proof.job_id = $_GET[jid]";
 $result = mysql_query($sql)
     or die('Invalid query: ' . $sql . ' - Error is ' . mysql_error());
  
 $sql = "UPDATE `users`,`proof`
    SET user_earning = user_earning + perperson
  WHERE users.id = $id
  AND proof.job_id = $_GET[jid]";
 $result = mysql_query($sql)
     or die('Invalid query: ' . $sql . ' - Error is ' . mysql_error());
  
  
 $sql = "UPDATE `users`
    SET jobs_completed = jobs_completed + 1
  WHERE id = $id";
 $result = mysql_query($sql)
     or die('Invalid query: ' . $sql . ' - Error is ' . mysql_error());
     
 
 
header( "Location: http://www.myurl.com/jobproof.php?ID=$_REQUEST[jid]") ;
?>
Although it appears to be redirecting back to the last page the queries are not being run so no values are being changed. Any guidence please?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Redirection after script complete.

Post by califdon »

Try:

Code: Select all

header( "Location: http://www.myurl.com/jobproof.php?ID=".$_REQUEST['jid']) ;
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Redirection after script complete.

Post by synical21 »

Thank you it works :) :drunk:
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Redirection after script complete.

Post by califdon »

You're welcome. Glad it resolved your problem. Only simple $variables are interpreted within double quotes. Arrays, functions, etc. are not, so you have to concatenate them with the rest of the string. Also, array indexes (that's what the part inside the square brackets is) must be quoted strings or variables.
Post Reply