frank_solo Posted May 5, 2013 Share Posted May 5, 2013 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 Quote Link to comment Share on other sites More sharing options...
DavidAM Posted May 5, 2013 Share Posted May 5, 2013 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. Quote Link to comment Share on other sites More sharing options...
frank_solo Posted May 5, 2013 Author Share Posted May 5, 2013 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.phpI 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 2Warning: 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 9Warning: 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" Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 5, 2013 Share Posted May 5, 2013 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. We also have a sticky thread with how to handle these errors. Quote Link to comment Share on other sites More sharing options...
frank_solo Posted May 5, 2013 Author Share Posted May 5, 2013 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"); } ?> Quote Link to comment Share on other sites More sharing options...
DavidAM Posted May 6, 2013 Share Posted May 6, 2013 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' ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.