Jump to content

[SOLVED] Javascript Nested in Php?


ballhogjoni

Recommended Posts

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

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;
}
}
?>

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.'" />';
					}
				}?>

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.'" />';
}
?>

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.