Jump to content

[SOLVED] header redirect problem .


imarockstar

Recommended Posts

 

im trying to redirect my page after some database updates ..

 

here is the link:  http://dfwdrives.com/

 

after you click on a tag you go here : http://dfwdrives.com/out.php

 

 

here is the code thats NOT working ... any help would be rad !!!

(everything works fine except the redirect)

im running php 5

 

<?




$getcount = mysql_query("SELECT * FROM cloud where tag='$_GET[tag]'"); 
$result = mysql_query($query);

while ($result=mysql_fetch_array($getcount)){

$new_count = ($result[count] + 1); 
//adds one to the number from num_votes column

$addy = "http://www.yahoo.com";

$update_rating = mysql_query("UPDATE the_cloud SET count='$new_count' where tag='$_GET[tag]'"); 
//this updates the specific row in the database that is concerned. Change the table name to fit yours.



}



header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/104490-solved-header-redirect-problem/
Share on other sites

I would do it like this: (by the way, what's '$addy = "http://www.yahoo.com";' for??)

 

<?php

$tag=$_GET['tag'];


$result = mysql_query("SELECT * FROM cloud where tag='$tag'")
or die(mysql_error());

while($row = mysql_fetch_array( $result )) {

$new_count = ($row[count] + 1); 
//adds one to the number from num_votes column

$query="UPDATE the_cloud SET count='$new_count' where tag='$tag'"; 
mysql_query($query);
//this updates the specific row in the database that is concerned. Change the table name to fit yours.



}



header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

Most of that code is not needed, making your script VERY inefficient.

 

<?php

if (isset($_GET['tag'])) {
  $tag = mysql_real_escape_string($_GET['tag']);
  $sql = "UPDATE the_cloud SET count=count+1 WHERE tag='$tag'";
  if (mysql_query($sql)) {
    header("Location: http://www.example.com/");
    exit();
  } else {
    echo mysql_error();
  }
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.