Jump to content

Redirect to url


frank_solo

Recommended Posts

Alright so I'm trying to create a redirect script where it determines where to direct the user based on what the column equals to. Can anyone please "direct" me in how to accomplish this? This what I have so far:

<?
include('config.php');
include('lock.php');
include('timeout.php');
$db_name=""; // Database name 
$tbl_name=""; // Table name

// Connect to server and select database.

mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];


// Retrieve data from database 
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);

$a = "apteditform.php?id=".$rows['id']."";
$b = "commeditform.php?id=".$rows['id']."";


$unit = "".$rows['unit']."";

if ( "$unit == 'Apartment'" )
  {
  header ("Location: $a");
  }
  elseif ( "$unit == 'Commercial'" )
  {
  header ("Location: $b");
  }

?>

Thanks

Link to comment
Share on other sites

What is the problem? Tell us what it is doing that is should NOT do, or what it is NOT doing that it should.

 

Turn on error reporting (at the beginning of the script) so you can see if there are any error messages

error_reporting(E_ALL);
ini_set('display.errors', 1);
Don't use short tags "<?" use full tags instead "<?php" -- some servers do not support short tags.

 

Make sure there is absolutely no output before the header() calls (like maybe from the included files).

 

Technically, a Location header is supposed to have a full url. i.e. http://www.domain.com/apteditform.php?id=1.

Link to comment
Share on other sites

What I would like it to do is if the column equals to "Apartments" then to direct the user to apteditform.php or if the Column equals to "Commercial" then direct the user to commeditform.php

I added error reporting and this is what it reads:

"Notice: A session had already been started - ignoring session_start() in /home/content/84/10858584/html/user/timeout.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /home/content/84/10857784/html/user/timeout.php:2) in /home/content/84/10858584/html/user/timeout.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at /home/content/84/10857784/html/user/timeout.php:2) in /home/content/84/10858584/html/user/redirectedit.php on line 33"

Link to comment
Share on other sites

Ok Thanks guys but I have done both changes and it still selects $a = "http://user.mydomain.co/apteditform.php?id=".$rows['id']."";

These are the changes

<?php
error_reporting(E_ALL);
ini_set('display.errors', 1);
include('config.php');


$db_name=""; // Database name 
$tbl_name=""; // Table name

// Connect to server and select database.

mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];


// Retrieve data from database 
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);

$a = "http://user.mydomain.co/apteditform.php?id=".$rows['id']."";
$b = "http://user.mydomain.co/commeditform.php?id=".$rows['id']."";


$unit = "".$rows['unit']."";

if ( "$unit == 'Apartment'" )
  {
  header ("Location: $a");
  }
  elseif ( "$unit == 'Commercial'" )
  {
  header ("Location: $b");
  }

?>
Link to comment
Share on other sites

 

if ( "$unit == 'Apartment'" )
  {
  header ("Location: $a");
  }
  elseif ( "$unit == 'Commercial'" )

 

What the heck is that? Why do you have the condition you want to test in quotes? That IF statement is checking to see if the string is not empty. It is not empty because it contains "$unit == 'Apartment'" (literally).

 

if ( $unit == 'Apartment' )
  {
  header ("Location: $a");
  }
  elseif ( $unit == 'Commercial' )
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.