Forum Moderators: coopster

Message Too Old, No Replies

Redirection of pages in php

after satisfying the conditions page will redirect to specified link

         

manoj badola

4:21 pm on Mar 18, 2004 (gmt 0)

10+ Year Member



First it check the text field, if the text field are not matched with your database values then after cliking the submit button it will show the error message in the same page , but if it matched then it will redirect to the specified page/link.

coopster

8:12 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, manoj badola!

Have you had a look at the PHP header [php.net] function?

if (text field = database value) { 
header("Location: [example.com...] /* Redirect browser */
exit;
}
// otherwise, format your error message and display the form again.

AjiNIMC

8:20 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome Badola to the forum,

if ($password = "aji") {
header("Location: [xyz.com...]
exit;
}
else
{
header("Location: [xyz.com...]
or
echo "Error message"; /on the same page error message/
}

Aji

mbcx9rvt

1:42 am on Mar 19, 2004 (gmt 0)

10+ Year Member



Hi, and welcome.

Something like the following is the complete version of what you want:


<?php

//setup a connection to the database
$db = mysql_connect("server", "user", "pass");
mysql_select_db("database", $db);

//Assuming the information is brought from a <form> and
//that you use the POST method, we can do the following

//This sets the information from the form into an easy
//to use variable

$input_data = $_POST['data_from_form'];

//now we need to create a MySQL query to test if the
//data in $input_data matches what we have in our db

$sql = "SELECT * FROM table_name WHERE some_variable = '".$input_data."'";

//What we have done here is say that we want to select
//all (*) the records from our database table that
//match our input data

//Now we have to format the output from MySQL so that
//we can use it. If this response is '0' then we know
//that this item is not in the database. If it is
//Greater than or equal to 1, then it is in the db

$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$some_variable= $row["some_variable"];
}

//now we need to do an if() function to find out if
//this value is 0 or >0

if($some_variable = '0'){
header("Location: http://www.example.com/error.php"); /* Redirect browser to your error page */
exit;
}else{
header("Location: http://www.example.com/success_page.php"); /* Redirect browser somewhere good! */

}


I hope this helps! Once again, welcome to the Forum!

mbcx9rvt
exit;