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>"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/ 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; } } ?> Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238146 Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Author Share Posted April 25, 2007 Crrap it didn't redirect Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238168 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.'" />'; } }?> Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238192 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. Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238200 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? Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238202 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.'" />'; } ?> Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238203 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. Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238206 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... Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238219 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. Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238224 Share on other sites More sharing options...
ballhogjoni Posted April 25, 2007 Author Share Posted April 25, 2007 Nice Taith, You solved it! Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238227 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(); Link to comment https://forums.phpfreaks.com/topic/48632-solved-javascript-nested-in-php/#findComment-238333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.