I'm new to PHP - after doing a lot of ASP and I'm stumbling on a few issues.
The first issue I have is redirecting to a new page during error handling.
I have the following code:
<?php
session_start();
$error_text = $_SESSION['dberror'];
include 'inc/dbconnect.php';
include 'inc/session_handle.php';
?>
dbconnect.php establishes the connection to the database.
If there's an error, I'd like to redirect to a friendly error page, since the code can't continue.
my dbconnect.php page looks like this:
<?php
$conn = mysql_connect("localjost","root"); //misspelled to trigger error
if (!$conn)
{
$_SESSION['dberror'] = mysql_error();
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'localjost' (1) in /Applications/XAMPP/xamppfiles/htdocs/mysite/inc/dbconnect.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/mysite/inc/dbconnect.php:3) in /Applications/XAMPP/xamppfiles/htdocs/mysite/inc/dbconnect.php on line 9
In ASP this was pretty easy to code. i could redirect people to however many pages I needed to based on what error was triggered. It doesn't appear that I can do that in PHP.
(or, at least it appears I need to do it in a much different way.)
Thank you both for your help!
There are a lot of things I like about PHP - and although I dabbled in ASP.NET, it seems PHP does what I need. If I can get around the strange things :)
Thanks for the link - I'll read up on that!
Ray Paseur
Thanks for the points. You'll love the SitePoint book. Very readable with great examples. ~Ray
There are a lot of things I like about PHP - and although I dabbled in ASP.NET, it seems PHP does what I need. If I can get around the strange things :)
Thanks for the link - I'll read up on that!