ballhogjoni Posted April 25, 2007 Share Posted April 25, 2007 Is there a way to put javascipt in this block of php code to redirect to another page? Or does anyone have a better way of doing a redirect when this block of code is executed? The header() won't work since headers have been set already. <?php if (isset($money)) { $sql = mysql_query("SELECT * FROM contactinfo LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ if (isset($row['fname'])) { mysql_query("INSERT INTO dispo_Money (Name, Phone, Email, Position, State, Comments) VALUES ('$row[fname] $row[lname]','$row[areacode]$row[prefix]$row[linenumber]','$row[email]','$row[position]','$row[state]','$comments')"); // mysql_query("DELETE FROM contactinfo WHERE email='$row[email]'"); echo "<script } elseif (!isset($row['fname'])) { echo "<p align=\"center\">Don't Forget To Disposition the Lead.</p>"; } else { echo "<p align=\"center\"><font color=\"red\"><b>What the crap, an error! Go talk to Chris</b></font></p>"; } } } ?> Quote Link to comment Share on other sites More sharing options...
taith Posted April 25, 2007 Share Posted April 25, 2007 scratch header()... too problimatic... use this... <? function redirect($filename="?", $delay="0", $die="0"){ if((!headers_sent())&&($delay=="0")) header('Location: '.$filename); elseif($delay=="0"){ echo '<script type="text/javascript">'; echo 'window.location.href="'.$filename.'";'; echo '</script>'; echo '<noscript>'; echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />'; echo '<noscript>'; }else echo '<meta http-equiv="refresh" content="'.$delay.';url='.$filename.'" />'; if($die=="0"){ db_disconnect(); exit; } } ?> Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Author Share Posted April 25, 2007 Crrap it didn't redirect Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Author Share Posted April 25, 2007 Does anybody know why this code is not redirecting to the $filename variable? <?php if (isset($money)) { $sql = mysql_query("SELECT * FROM contactinfo LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ if (isset($row['fname'])) { mysql_query("INSERT INTO dispo_Money (Name, Phone, Email, Position, State, Comments) VALUES ('$row[fname] $row[lname]','$row[areacode]$row[prefix]$row[linenumber]','$row[email]','$row[position]','$row[state]','$comments')"); // mysql_query("DELETE FROM contactinfo WHERE email='$row[email]'"); function redirect($filename="http://www.xxxxxx.php", $delay="0", $die="0"){ if((!headers_sent())&&($delay=="0")) { header("Location:$filename"); } elseif($delay=="0"){ echo '<script type="text/javascript">'; echo 'window.location.href="'.$filename.'";'; echo '</script>'; echo '<noscript>'; echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />'; echo '<noscript>'; } else { echo '<meta http-equiv="refresh" content="'.$delay.';url='.$filename.'" />'; } }?> Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 25, 2007 Share Posted April 25, 2007 I always use output buffering so I can set headers anywhere in my code. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Author Share Posted April 25, 2007 What do you mean? How do you do that? Quote Link to comment Share on other sites More sharing options...
taith Posted April 25, 2007 Share Posted April 25, 2007 if(isset($money)){ $sql = mysql_query("SELECT * FROM contactinfo LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ if(isset($row['fname'])){ mysql_query("INSERT INTO dispo_Money (Name, Phone, Email, Position, State, Comments) VALUES ('$row[fname] $row[lname]','$row[areacode]$row[prefix]$row[linenumber]','$row[email]','$row[position]','$row[state]','$comments')"); // mysql_query("DELETE FROM contactinfo WHERE email='$row[email]'"); redirect("http://www.xxxxxx.php"); } } } function redirect($filename="?", $delay="0", $die="0"){ if((!headers_sent())&&($delay=="0")) header("Location:$filename"); elseif($delay=="0"){ echo '<script type="text/javascript">'; echo 'window.location.href="'.$filename.'";'; echo '</script>'; echo '<noscript>'; echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />'; echo '<noscript>'; }else echo '<meta http-equiv="refresh" content="'.$delay.';url='.$filename.'" />'; } ?> Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Author Share Posted April 25, 2007 Taith the problem wiht doing that is that I need it to redirect within that if else statement because it should only redirect if that if statement is true. Quote Link to comment Share on other sites More sharing options...
taith Posted April 25, 2007 Share Posted April 25, 2007 then move the redirect("url") wherever you want it... Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Author Share Posted April 25, 2007 my bad I didn't see the url there. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Author Share Posted April 25, 2007 Nice Taith, You solved it! Quote Link to comment Share on other sites More sharing options...
taith Posted April 25, 2007 Share Posted April 25, 2007 cheers... that function is great! always use it over header(); 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.