Redirect to url

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:

[php]<?
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”);
}

?>[/php]

Thanks

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"

Ok so this is what I have done so far but I still get directed oly to
$a = “http://user.mydomain.co/apteditform.php?id=".$rows[‘id’]."”;

Here are the changes thus far.
[php]<?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”);
}

?>[/php]

You have a serious logic/syntax issue on the following lines:
[php]
if ( “$unit == ‘Apartment’” )
{
header (“Location: $a”);
}
elseif ( “$unit == ‘Commercial’” )
{
header (“Location: $b”);
}[/php]

The following:
[php]"$unit == ‘Apartment’"[/php]
Always evaluates to true. Remove the quotations around it and it will work. For the record, PHP considers a non-empty string as truthy - and by encapsulating everything in quotes, you’re treating the statement as a string literal instead of actually evaluating it.

Change the lot to this:
[php]
if ( $unit == ‘Apartment’ )
{
header (“Location: $a”);
}
elseif ( $unit == ‘Commercial’ )
{
header (“Location: $b”);
}[/php]

But bear in mind that $unit WILL be case-sensitive.

Thank You! YES that solved the issue. I will be aware of the case sensitivity. Thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service