Help with php redirect.

Help with php redirect.

am 10.12.2006 16:13:55 von Chris Carter

I need to put an else condition in the below code. So that if a data is not
found after the search is executed by the user, he/she is redirected to a
sorry page. Don't know how to do it, please advice.

Please note that this code is working absolutly fine, its just that I tried
various combination of ifelse conditions but could not sort it out.

The code:








// database information
$host = 'localhost';
$user = 'xxxx';
$password = 'xxxx';
$dbName = 'xxxx';
$hello = $_REQUEST['hello'];

mysql_connect(localhost,$user,$password);
@mysql_select_db($dbName ) or die( "Sorry But There Seems To Be A Problem
Connecting To The Database");

$query="SELECT * FROM xxxx WHERE hello = '$hello'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$showThis=mysql_result($result,$i,"showThis");


echo "

$showThis

";

$i++;
}
?>



So, if the showThis is not achieved or if the user puts it wrong data ... he
should be redirected to an error page or should get an error message on the
same result page, instead of the blank table.

How to achieve this, please advice.

Thanks in advance
--
View this message in context: http://www.nabble.com/Help-with-php-redirect.-tf2789498.html #a7782639
Sent from the Php - Database mailing list archive at Nabble.com.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Help with php redirect.

am 10.12.2006 16:27:22 von Niel Archer

Hi

before you can use an 'else' you'd need an 'if'

However you can do it without either. Your while will be bypassed if no
rows are returned. so after the while add:

if ($num == 0){

echo "

No Results found
";

}


As for redirection. Doesn't seem to be possible if you've already
started outputting the table as your code implies

Niel

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Help with php redirect.

am 10.12.2006 17:26:52 von Chris Carter

this works ... but the table headings are getting displayed with the sorry
message.


Chris Carter wrote:
>
> I need to put an else condition in the below code. So that if a data is
> not found after the search is executed by the user, he/she is redirected
> to a sorry page. Don't know how to do it, please advice.
>
> Please note that this code is working absolutly fine, its just that I
> tried various combination of ifelse conditions but could not sort it out.
>
> The code:
>
>
>
>
>
>
>
> >
> // database information
> $host = 'localhost';
> $user = 'xxxx';
> $password = 'xxxx';
> $dbName = 'xxxx';
> $hello = $_REQUEST['hello'];
>
> mysql_connect(localhost,$user,$password);
> @mysql_select_db($dbName ) or die( "Sorry But There Seems To Be A Problem
> Connecting To The Database");
>
> $query="SELECT * FROM xxxx WHERE hello = '$hello'";
> $result=mysql_query($query);
>
> $num=mysql_numrows($result);
>
> mysql_close();
>
> $i=0;
> while ($i < $num) {
>
> $showThis=mysql_result($result,$i,"showThis");
>
>
> echo "
>
> $showThis
>
> ";
>
> $i++;
> }
> ?>
>
>
>
> So, if the showThis is not achieved or if the user puts it wrong data ...
> he should be redirected to an error page or should get an error message on
> the same result page, instead of the blank table.
>
> How to achieve this, please advice.
>
> Thanks in advance
>

--
View this message in context: http://www.nabble.com/Help-with-php-redirect.-tf2789498.html #a7783269
Sent from the Php - Database mailing list archive at Nabble.com.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php