Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirection in PHP

Status
Not open for further replies.

funkygeezer1975

Technical User
Dec 14, 2004
22
GB
See below my code now i can get the redirection to work using the header(location: url)
<?php
$user = addslashes($_POST['username']);
$pass = $_POST['password'];
$dbHost = "localhost";
$dbUser = "$user";
$dbPass = "$pass";
$dbDatabase = "goodsin";
if (empty($user) || empty($pass)) {
header( "Location: loginretry.html" );
}


else{
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Login Failed");

mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

echo"Welcome to goods in";}
?>
<script language="JavaScript"><!--
setTimeout('Redirect()',500);
function Redirect()
{
location.href = 'index.html';
}
// --></script>

i just cant seem to get how to redirect if the mysql_connect fails
any suggestions much appreciated
 
funkygeezer1975,

Have you tried changing the line

$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Login Failed");

to

$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Login Failed", mysql_error());


What version of PHP, MySql, and what OS are you using?


Wishdiak
A+, Network+, MCSA 2003 certified
 
Hi Wishdiak

iI am using xp pro sp2, Mysql 1.4 and php 4.3.3

can I use another header in here $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Login Failed");

or is there another way of rediecting back to loginretry.html if the mysql_connect fails.

sorry im a bit of a newbie
 
funkygeezer1975,

You could always wrap your mysql_connect statement inside of a conditional.

Such as:

if (mysql_connect("$dbHost", "$dbUser", "$dbPass"))
{
Code:
 }
else
 {
 header( "Location: loginretry.html");
 }


Wishdiak
A+, Network+, MCSA 2003 certified
[URL unfurl="true"]http://www.wishdiak.com[/URL]
 
Excellent all works great now many thanks for you help you will be mentioned(if you dont mind) as this is college assignment.
many thanks for your help.
 
funkygeezer1975,

I'm glad it worked :) Next time that you have a php question, you might want to ask it in the php forum.

Just a suggestion, I'm glad it worked, and feel free to mention me.

Wishdiak
A+, Network+, MCSA 2003 certified
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top