Jump to content

PHP Passing variables and header redirect


kamal213

Recommended Posts

Thanks for your reply I successfully pass the variable using the $_GET! However I cant get it to redirect to the $test, it redirects to my home page instead!

 

(p.s my index.php isn't my home page I use it for something else..weird but thats the case)

Kool here it goes:

 

<?php 
			$x = $_SERVER['REQUEST_URI'];
			preg_match('/\/[a-z0-9]+.php/', $x, $match);  
			$page = array_shift($match);
			$page = ltrim($page, '/');
			global $page; 
			?>

 

The above code gets the current page's url and strips it to just the file name i.e. index.php

 

<a href="customers.php?id=' . $c_id . '&rid=' . $page . '"> ' . $c_name . '</a>

 

I the pass the file name in the above variable.

 

session_start(); 
if(isset($_GET['id']) && $_GET['rid']){
// Connect to the MySQL database  
include "leadscript/connect_to_mysql.php"; 
//This will check to see the URL variable is set and it exists in the db
$check_id = preg_replace('#[^0-9]#i', '', $_GET['id']);
                $page_url = $_GET['id'];



if(isset($_POST['submit'])) {
$check_id = mysql_real_escape_string($_POST['thisID']);
$c_name = mysql_real_escape_string($_POST['c_name']);
$c_pbo = mysql_real_escape_string($_POST['c_pbo']);
$c_callbackcomplete = mysql_real_escape_string($_POST['c_callbackcomplete']);
$submit = mysql_real_escape_string($_POST['submit']);


$insert=mysql_query("UPDATE customer SET c_name= '$c_name', c_pbo='Dead', c_callbackcomplete= 'COMPLETE', c_pbodate=now() WHERE c_id='$check_id' ")or die(mysql_error());

header("location: $page_url"); 
} 

 

Then the above code post to my database table - Its posts to the database fine, but just keeps redirecting to my home page instead hope this helps

YES!! Iz iz working yah!!! lol its ok!

 

What I had to do was create a hidden input field in my posting form, make sure is set by defining a post variable, the use the post variable in my header function like so:

 

<form action="deadleads.php" id="form2" name="form2" method="POST" target="_self">
						<table>
						<tr><td colspan="2"><input name="page_url" type="hidden" value="' . $page_url . '" /></td></tr>
						<tr><td><input type="submit" name="submit" value="Continue"/></td></tr>
						</table>
						</form>';

 

$page_url= mysql_real_escape_string($_POST['page_url']);]

 

header("Location: $page_id");

 

And it works like a charm! Thanks for your help sergeiSS!

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.