imarockstar Posted May 7, 2008 Share Posted May 7, 2008 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; ?> Quote Link to comment Share on other sites More sharing options...
smartin1017 Posted May 7, 2008 Share Posted May 7, 2008 Try this... header('Location:http://www.example.com/'); I am pretty sure you need to use single quotes inside the () Quote Link to comment Share on other sites More sharing options...
imarockstar Posted May 7, 2008 Author Share Posted May 7, 2008 nope lol .. that was not it ... Quote Link to comment Share on other sites More sharing options...
benphp Posted May 7, 2008 Share Posted May 7, 2008 Is that your entire script? Are you using print or echo anywhere? That will foul things up. Quote Link to comment Share on other sites More sharing options...
imarockstar Posted May 7, 2008 Author Share Posted May 7, 2008 thats the entire script ... for out.php no print and no echo ... it just updates the DB then neads to redirect .. Quote Link to comment Share on other sites More sharing options...
realjumper Posted May 7, 2008 Share Posted May 7, 2008 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; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted May 7, 2008 Share Posted May 7, 2008 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(); } } ?> Quote Link to comment Share on other sites More sharing options...
realjumper Posted May 7, 2008 Share Posted May 7, 2008 Most of that code is not needed, making your script VERY inefficient. Yes, your way is more efficient, no doubt about it...my way would work though ;-) Quote Link to comment Share on other sites More sharing options...
trq Posted May 7, 2008 Share Posted May 7, 2008 my way would work though Indeed, just not at all well. Quote Link to comment Share on other sites More sharing options...
ThYGrEaTCoDeR201 Posted May 7, 2008 Share Posted May 7, 2008 sometimes you may have to use ob_start(); if you don't want to get a bunch of errors. Quote Link to comment Share on other sites More sharing options...
imarockstar Posted May 8, 2008 Author Share Posted May 8, 2008 ok kool guys I shall try this ... ya my code prob sucked ass ... Im a beginner .. and Im still learning .. so thanks for you help .. I will let you know if it works .. rock on Quote Link to comment Share on other sites More sharing options...
imarockstar Posted May 8, 2008 Author Share Posted May 8, 2008 what the fuck .. thats still not working ... im not sure why any of the header redirects are not working .. Do I need to have something turned on in my php configuration ? Quote Link to comment Share on other sites More sharing options...
imarockstar Posted May 8, 2008 Author Share Posted May 8, 2008 ok it works .... i figured it out !!! thanks guys !!! Quote Link to comment Share on other sites More sharing options...
smartin1017 Posted May 8, 2008 Share Posted May 8, 2008 I ran into a problem like this once and the answer was to replace the capital L on Location with a lowercase. I never understood why but it worked. Try that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.