Page 1 of 1
Help : how can I open a new page in php
Posted: Tue May 01, 2007 4:36 pm
by rana
Hello,
I m facing a problem. I m trying to get information from my sql database, and i want, if possible, to open a new page when an error occurs.
Any idea on how can i open a new page in php ?
Thx in advance
[/syntax]
Posted: Tue May 01, 2007 4:38 pm
by hawleyjr
Hello Rana, welcome to the forum. Please read the forum rules.
Posted: Tue May 01, 2007 4:39 pm
by Oren
Open a new page with PHP? There's no such thing dude. Please try to explain better and be more specific as to what your problem is.
Post some code if needed too (and use the PHP tags we have here so it will be highlighted) - but don't post here the whole code though, just the relevant part

Posted: Tue May 01, 2007 4:41 pm
by RobertGonzalez
Opening new pages is done in the client, not on the server. What you want to do would have to be done with Javascript or something along those lines.
Posted: Tue May 01, 2007 4:44 pm
by rana
hey,
(in fact i m a girl

)
Well to be more explicit, here 's my problem :
I have 2 pages :
page one is a form and when the user click on submit, it opens an php page that should insert into my sql database information like this
Code: Select all
<?php
function insertResa ()
{
$FirstName= $_POST['Itm_8_00_3'];
$LastName= $_POST['Itm_8_00_5'];
$Nationality = $_POST['Itm_8_00_6'];
$Email= $_POST['Itm_8_00_7'];
$PhoneNumber=$_POST['Itm_8_00_8'];
$req="insert into client (FirstName,LastName, Nationality, Email, PhoneNumber) values ('$FirstName','$LastName', '$Nationality', '$Email', '$PhoneNumber')";
include 'Connexion.php';
$creer = mysql_query($req) or die ('Erreur d insertion'.mysql_error());
if ($creer)
{
echo "ok";
}
else
{
echo "Error inserting client";
}
?>
instead of having my message "error insert ..." i wanna open a new page with a specific message
thx

Posted: Tue May 01, 2007 4:46 pm
by Oren
Code: Select all
header("Location: http://path/to/error_page.html")
may be of interest.
Welcome by the way

Posted: Tue May 01, 2007 4:47 pm
by RobertGonzalez
Keep in mind that header to a new location will not open a new window, it will just redirect the currently focused window to another page.
What you could do is echo out some javascript in that else block that would open a window for you.
Re: Help : how can I open a new page in php
Posted: Tue May 01, 2007 4:48 pm
by vimadeva
rana wrote:Hello,
I m facing a problem. I m trying to get information from my sql database, and i want, if possible, to open a new page when an error occurs.
Any idea on how can i open a new page in php ?
Thx in advance
[/syntax]
I think you could use this:
Code: Select all
if($yourError == true){
echo '<meta http-equiv="REFRESH" content="0;url=errorPage.php">';
}
That code sends you to errorPage.php in 0 seconds, you can change the time to wait until redirect there. Its an html tag!!!
Posted: Tue May 01, 2007 4:52 pm
by RobertGonzalez
rana wrote:Any idea on how can i open a new page in php
Opening a page and redirecting to a page are two different things. Which are we talking about here?
Posted: Tue May 01, 2007 4:54 pm
by rana
Everah | Edited this post to reflect how we would like it to look.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
[s]thx[/s]
Thanks for [s]ur[/s]
your tips but [s]i[/s]
I couldn t make them work.
In fact [s]ur[/s]
you're right, [s]i[/s]
I don t want to open a new page but redirect it to my new page error.html
[s]thx[/s]
Thanks for [s]ur[/s]
your help
Posted: Tue May 01, 2007 5:05 pm
by RobertGonzalez
Redirects can be handled using
header(). Just make sure you use a full URI.
Posted: Tue May 01, 2007 5:40 pm
by superdezign
Rana wrote:(in fact i m a girl

)
Yeah, last I checked, Rana IS a girl's name.
Everah wrote:Redirects can be handled using
header(). Just make sure you use a full URI.
You have to use a full URI? Why? What's wrong with relative redirection?
Posted: Tue May 01, 2007 6:06 pm
by RobertGonzalez
Click on the link to the manual page for
header() and you'll find this a few scrolls down:
Note: HTTP/1.1 requires an absolute URI as argument to ยป Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:
Posted: Tue May 01, 2007 6:11 pm
by superdezign

Well then.
Hopefully it's not that big of a problem, because ever website that I've made in PHP (a few dozen) that has redirection uses relative redirection. Yeah, I really hope it doesn't cause a problem.
Posted: Tue May 01, 2007 6:21 pm
by RobertGonzalez
Have a look at the response headers one of these days. If you see:
Then you may want to look at moving to the HTTP 1.1 spec which is full URI.