Jump to content

PHP Passing variables and header redirect


kamal213

Recommended Posts

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

Link to comment
Share on other sites

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!

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.