Jump to content

Making a redirect faster when posting to same page


jjmusicpro

Recommended Posts

dont know whats going on now, it was working, now it wont work, i didnt change anything....

 

.

<?php
require_once ('connect.php'); 
require_once ('opendb.php'); 
$groupid_sent = $_GET['groupid'];
$query = "SELECT * FROM metrogroups WHERE groupid='$groupid_sent'"; 
$result = @mysql_query ($query); 
$count = mysql_num_rows($result); //number of results 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
$groupname = $row['groupname'] ;
?> 
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){ 
$zipcode = $_POST['zipcode_entered_search']; 
$query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
$result2 = mysql_query($query2); 
$query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
$result = @mysql_query ($query); 
$count = mysql_num_rows($result); 
if($count=="0"){ 
echo "<meta http-equiv=\"Refresh\" content=\"0;url=nf.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">";
}else if($count=="1"){ 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
$site = $row['redirect_url'] ;
header("location:$site");
}}else{ 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
echo "<meta http-equiv=\"Refresh\" content=\"0;url=shared.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">";
};}}else{}?>

Link to comment
Share on other sites

ALl the process page should do is 3 things

 

1. if there is 0 results, go to page nf.php

2. if there is only 1 result, go to the url from db

3. if there is more then 1 result go to shared.php

 

all that is happening is when i POST to process.php its a blank page.

 

cant get it to work

 

<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){ 
$zipcode = $_POST['zipcode_entered_search']; 
$query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
$result2 = mysql_query($query2); 
$query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
$result = @mysql_query ($query); 
$count = mysql_num_rows($result); 
if($count=="0"){ 
echo "<meta http-equiv=\"Refresh\" content=\"0;url=nf.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">";
}else if($count=="1"){ 
$site = $row['redirect_url'] ;
echo("location:$site");
exit;
}else{ 
echo "<meta http-equiv=\"Refresh\" content=\"0;url=shared.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">";
}}else{}?>

Link to comment
Share on other sites

as far as i can tell the code you posted shouldn't even compile and should display an error like "unexpected end". do you have errors turned off? your braces don't match. It's MUCH easier to see if you indent your code:

 

require_once ('connect.php'); 
require_once ('opendb.php'); 
$groupid_sent = $_GET['groupid'];
$query = "SELECT * FROM metrogroups WHERE groupid='$groupid_sent'"; 
$result = @mysql_query ($query); 
$count = mysql_num_rows($result); //number of results 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
$groupname = $row['groupname'] ;

if($_SERVER['REQUEST_METHOD'] == "POST"){ 
	$zipcode = $_POST['zipcode_entered_search']; 
	$query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
	$result2 = mysql_query($query2); 
	$query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
	$result = @mysql_query ($query); 
	$count = mysql_num_rows($result); 

	if($count=="0"){ 
		echo "<meta http-equiv=\"Refresh\" content=\"0;url=nf.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">";
	} else if($count=="1") { 
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
			$site = $row['redirect_url'] ;
			header("location:$site");
		}
	} else { 
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
			echo "<meta http-equiv=\"Refresh\" content=\"0;url=shared.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">";
		};
	}
} else {}

// WHERE IS THE CLOSE OF THE while loop at the top??

 

also, you won't know if mysql_query() is the problem because you hide any errors. i'd change it to this:

 

$result = mysql_query($query) or die(mysql_error());

 

add: if you don't know whether errors are turned on or off, add this to the top of your script:

 

<?php ini_set('error_reporting', PHP_INI_ALL); ?>

Link to comment
Share on other sites

still a blank page when i put that at the top

 

<?php ini_set('error_reporting', PHP_INI_ALL); ?>
<?php
require_once ('connect.php'); 
require_once ('opendb.php'); 
$groupid_sent = $_GET['groupid'];
$query = "SELECT * FROM metrogroups WHERE groupid='$groupid_sent'"; 
$result = @mysql_query ($query); 
$count = mysql_num_rows($result); //number of results 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
$groupname = $row['groupname'] ;

if($_SERVER['REQUEST_METHOD'] == "POST"){ 
	$zipcode = $_POST['zipcode_entered_search']; 
	$query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
	$result2 = mysql_query($query2); 
	$query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
	$result = @mysql_query ($query); 
	$count = mysql_num_rows($result); 

	if($count=="0"){ 
		echo "<meta http-equiv=\"Refresh\" content=\"0;url=nf.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">";
	} else if($count=="1") { 
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
			$site = $row['redirect_url'] ;
			header("location:$site");
		}
	} else { 
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
			echo "<meta http-equiv=\"Refresh\" content=\"0;url=shared.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">";
		};
	}
} else {}
?>

Link to comment
Share on other sites

this should have your braces matched and unnecessary loops removed:

 

<?php
require_once ('connect.php'); 
require_once ('opendb.php'); 
$groupid_sent = $_GET['groupid'];
$query = "SELECT * FROM metrogroups WHERE groupid='$groupid_sent'"; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$groupname = $row['groupname'] ;

if($_SERVER['REQUEST_METHOD'] == "POST") {
$zipcode = $_POST['zipcode_entered_search']; 
$query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
$result2 = mysql_query($query2); 
$query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result); 

if($count=="0"){ 
	header( "location: nf.php?groupid=" . $_GET['groupid'] . "?zipcode_entered_search=" . $_GET['zipcode_entered_search'] ."\">");
	exit;
} else if($count=="1") { 
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	$site = $row['redirect_url'] ;
	header("location:$site");
	exit;
} else { 
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	header( "location: shared.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">");
	exit;
}
} else {
   // No POST, so do whatever we do if there is no POST.
   
}
?>

Link to comment
Share on other sites

still blank page

 

here is the form sending data to process.php

            <TD width="64%" height="47"><form action="process.php?groupid=<?php $groupid_sent = $_GET['groupid']; echo $groupid_sent ?>" method="POST">
                <div align="center">
                  <input  type="text" maxlength="10" class="searchBox" name="zipcode_entered_search"  size="8" />
                   
                  <input name="Submit" type="image" id="Submit" src="handyman_files/go_button.gif" alt="Request Service from your local Mr. Handyman!">
                </div>
            </form></TD>

 

here is complete process.php

<?php ini_set('error_reporting', PHP_INI_ALL); ?>
<?php
require_once ('connect.php'); 
require_once ('opendb.php'); 
$groupid_sent = $_GET['groupid'];
$query = "SELECT * FROM metrogroups WHERE groupid='$groupid_sent'"; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$groupname = $row['groupname'] ;

if($_SERVER['REQUEST_METHOD'] == "POST") {
$zipcode = $_POST['zipcode_entered_search']; 
$query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
$result2 = mysql_query($query2); 
$query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result); 

if($count=="0"){ 
	header( "location: nf.php?groupid=" . $_GET['groupid'] . "?zipcode_entered_search=" . $_GET['zipcode_entered_search'] ."\">");
	exit;
} else if($count=="1") { 
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	$site = $row['redirect_url'] ;
	header("location:$site");
	exit;
} else { 
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	header( "location: shared.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">");
	exit;
}
} else {
   // No POST, so do whatever we do if there is no POST.
   
}
?>

 

Link to comment
Share on other sites

try this

 

            <TD width="64%" height="47"><form action="process.php?groupid=<?php echo $_GET['groupid'];?>" method="POST">
                <div align="center">
                  <input  type="text" maxlength="10" class="searchBox" name="zipcode_entered_search"  size="8" />
                   
                  <input name="Submit" type="image" id="Submit" src="handyman_files/go_button.gif" alt="Request Service from your local Mr. Handyman!">
                </div>
            </form></TD>

 

<?php
error_reporting(E_ALL);
require_once ('connect.php'); 
require_once ('opendb.php'); 
$groupid_sent = (int)$_GET['groupid'];
$query = "SELECT * FROM metrogroups WHERE groupid=$groupid_sent"; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$groupname = $row['groupname'] ;

if( isset($_POST['Submit']) )
{
$zipcode = $_POST['zipcode_entered_search']; 
$query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
$result2 = mysql_query($query2); 
$query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result); 

switch($count)
{
	case 0:
		header( "location: nf.php?groupid=" . $_GET['groupid'] . "?zipcode_entered_search=" . $_GET['zipcode_entered_search'] ."\">");
		exit;
	break;
	case 1:
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		$site = $row['redirect_url'] ;
		header("location: $site");
		exit;
	break;
	default:
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		header( "location: shared.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">");
		exit;
	break;
}
} else {
echo "Nothing submitted!";
}
?>

Link to comment
Share on other sites

humm

 

change the form code to

            <TD width="64%" height="47"><form action="process.php?groupid=<?php echo $_GET['groupid'];?>" method="POST">
                <div align="center">
                  <input  type="text" maxlength="10" class="searchBox" name="zipcode_entered_search"  size="8" />
                   
                  <input name="Submit" type="image" src="handyman_files/go_button.gif" alt="Request Service from your local Mr. Handyman!">
                </div>
            </form></TD>

 

also i assume the php code is in a the called process.php

Link to comment
Share on other sites

yep...

 

still blank page...

 

this is my old code, all works fine, but want it to be faster with the header() calls...

 

<?php
	  
	  if($_SERVER['REQUEST_METHOD'] == "POST"){
	  
	       require_once ('connect.php'); 
  			 require_once ('opendb.php'); 

		 $groupid_sent = $_GET['groupid'];


	   $query = "SELECT * FROM metrogroups WHERE groupid='$groupid_sent'"; 
  $result = @mysql_query ($query); 
  $count = mysql_num_rows($result); //number of results 
  
  while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
$groupname = $row['groupname'] ;
}
	    }else{ 
     require_once ('connect.php'); 
  			 require_once ('opendb.php'); 

		 $groupid_sent = $_GET['groupid'];

	   $query = "SELECT * FROM metrogroups WHERE groupid='$groupid_sent'"; 
  $result = @mysql_query ($query); 
  $count = mysql_num_rows($result); //number of results 
  
  while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
$groupname = $row['groupname'] ;
}
  } 
?> 
<?php
  if($_SERVER['REQUEST_METHOD'] == "POST"){ 
  $zipcode = $_POST['zipcode_entered_search']; 
  $query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
  $result2 = mysql_query($query2); 
  $query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
  $result = @mysql_query ($query); 
  $count = mysql_num_rows($result); 

if($count=="0"){ 
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=nf.php\">";
exit;
}else if($count=="1"){ 

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
$site = $row['redirect_url'] ;
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$site\">";
}
}else{ 
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=shared.php\">"; 
} 
  }else{ 
  } 
?>

Link to comment
Share on other sites

if i change any of those lines to the header function like you said, i get a blank page

 

<?php
	  
	  if($_SERVER['REQUEST_METHOD'] == "POST"){
	  
	       require_once ('connect.php'); 
  			 require_once ('opendb.php'); 

		 $groupid_sent = $_GET['groupid'];


	   $query = "SELECT * FROM metrogroups WHERE groupid='$groupid_sent'"; 
  $result = @mysql_query ($query); 
  $count = mysql_num_rows($result); //number of results 
  
  while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
$groupname = $row['groupname'] ;
}
	    }else{ 
     require_once ('connect.php'); 
  			 require_once ('opendb.php'); 

		 $groupid_sent = $_GET['groupid'];

	   $query = "SELECT * FROM metrogroups WHERE groupid='$groupid_sent'"; 
  $result = @mysql_query ($query); 
  $count = mysql_num_rows($result); //number of results 
  
  while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
$groupname = $row['groupname'] ;
}
  } 
?> 
<?php
  if($_SERVER['REQUEST_METHOD'] == "POST"){ 
  $zipcode = $_POST['zipcode_entered_search']; 
  $query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
  $result2 = mysql_query($query2); 
  $query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
  $result = @mysql_query ($query); 
  $count = mysql_num_rows($result); 

if($count=="0"){ 
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=nf.php\">";
exit;
}else if($count=="1"){ 

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
$site = $row['redirect_url'] ;
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$site\">";
}
}else{ 
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=shared.php\">"; 
} 
  }else{ 
  } 
?>

Link to comment
Share on other sites

i just want to get thsi script here to kick out the results that match the zipcode entered

 

i just need it to kick out this when it goes to the page, but cant seem to get rid of all those else if's

 

}else{ 
     echo "<p><b>Make sure you contact the office in your territory!</b><br /><br><table width=\"400\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" valign=\"top\">"; 
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
     echo '<tr><td colspan=2 valign="middle">' . $row['company_name'] . '<br>' .$row['notes_1'] . '</b></td></tr><tr><td valign=top><img src=mm_smaller.gif></td><td>' .'<b>Phone:</b>'. ' ' . $row['phone_number'] . '<br>'.'<a href="'. $row['redirect_url'] . '"> Visit Website </a>'. ' ' .'</td></tr>'; 
    }echo '</table>';

 

		<?php
 if($_SERVER['REQUEST_METHOD'] == "POST"){ 
 $zipcode = $_POST['zipcode_entered_search']; 
 $query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
 $result2 = mysql_query($query2); 
 $query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
 $result = @mysql_query ($query); 
 $count = mysql_num_rows($result); 

if($count=="0"){ 
echo "<meta http-equiv=\"Refresh\" content=\"0;url=nf.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'] ."\">";
}else if($count=="1"){ 

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
$site = $row['redirect_url'] ;
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$site\">";
}
}else{ 
    echo "<p><b>Make sure you contact the office in your territory!</b><br /><br><table width=\"400\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" valign=\"top\">"; 
   while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
    echo '<tr><td colspan=2 valign="middle">' . $row['company_name'] . '<br>' .$row['notes_1'] . '</b></td></tr><tr><td valign=top><img src=mm_smaller.gif></td><td>' .'<b>Phone:</b>'. ' ' . $row['phone_number'] . '<br>'.'<a href="'. $row['redirect_url'] . '"> Visit Website </a>'. ' ' .'</td></tr>'; 
   }echo '</table>';
} 
 }else{ 
 } 
?>

Link to comment
Share on other sites

I wanted to take the zipcode_entered_searched thats being passed in the URL, and put that into the query, and kick out the results, by i cant get my syntax right

 

<?php
  $zipcode = $_GET['zipcode_entered_search']; 
  $query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
  $result2 = mysql_query($query2); 
  $query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
  $result = @mysql_query ($query); 
  $count = mysql_num_rows($result); 

echo "<p><b>Make sure you contact the office in your territory!</b><br /><br><table width=\"400\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" valign=\"top\">"; 
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
     echo '<tr><td colspan=2 valign="middle">' . $row['company_name'] . '<br>' .$row['notes_1'] . '</b></td></tr><tr><td valign=top><img src=mm_smaller.gif></td><td>' .'<b>Phone:</b>'. ' ' . $row['phone_number'] . '<br>'.'<a href="'. $row['redirect_url'] . '"> Visit Website </a>'. ' ' .'</td></tr>'; 
    }echo '</table>';
}
?>

Link to comment
Share on other sites

OK lets go back to this..

 

            <TD width="64%" height="47"><form action="process.php?groupid=<?php echo $_GET['groupid'];?>" method="POST">
                <div align="center">
                  <input  type="text" maxlength="10" class="searchBox" name="zipcode_entered_search"  size="8" />
                   
                  <input name="Submit" type="image" src="handyman_files/go_button.gif" alt="Request Service from your local Mr. Handyman!">
                </div>
            </form></TD>

 

 

 

<?php
error_reporting(E_ALL);
require_once ('connect.php'); 
require_once ('opendb.php'); 
$groupid_sent = (int)$_GET['groupid'];
$query = "SELECT * FROM metrogroups WHERE groupid=$groupid_sent"; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$groupname = $row['groupname'] ;

if( isset($_POST['Submit']) )
{
$zipcode = $_POST['zipcode_entered_search']; 
$query2 = "INSERT INTO zipcodes_searched (zipcode,time_date) VALUES ('$zipcode', NOW())";
$result2 = mysql_query($query2); 
$query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode' and on_off=1"; 
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result); 

switch($count)
{
	case 0:
		header( "location: nf.php?groupid=" . $_GET['groupid'] . "?zipcode_entered_search=" . $_GET['zipcode_entered_search']);
echo "location: nf.php?groupid=" . $_GET['groupid'] . "?zipcode_entered_search=" . $_GET['zipcode_entered_search']);
		exit;
	break;
	case 1:
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		$site = $row['redirect_url'] ;
		header("location: $site");
echo "location: $site";
		exit;
	break;
	default:
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		header( "location: shared.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search']);
echo "location: shared.php?groupid=" . $_GET['groupid'] . '?zipcode_entered_search=' . $_GET['zipcode_entered_search'];
		exit;
	break;
}
} else {
echo "Nothing submitted!";
}
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.