Help : how can I open a new page in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rana
Forum Newbie
Posts: 3
Joined: Tue May 01, 2007 4:33 pm

Help : how can I open a new page in php

Post 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]
Last edited by rana on Tue May 01, 2007 4:39 pm, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Hello Rana, welcome to the forum. Please read the forum rules.


[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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 :wink:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
rana
Forum Newbie
Posts: 3
Joined: Tue May 01, 2007 4:33 pm

Post 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 :)
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Code: Select all

header("Location: http://path/to/error_page.html")
may be of interest.

Welcome by the way :wink:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
vimadeva
Forum Newbie
Posts: 8
Joined: Tue May 01, 2007 3:51 pm

Re: Help : how can I open a new page in php

Post 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!!!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
rana
Forum Newbie
Posts: 3
Joined: Tue May 01, 2007 4:33 pm

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Redirects can be handled using header(). Just make sure you use a full URI.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Rana wrote:(in fact i m a girl :wink: )
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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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:
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

:oops: 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have a look at the response headers one of these days. If you see:

Code: Select all

HTTP/1.1 200 OK
Then you may want to look at moving to the HTTP 1.1 spec which is full URI.
Post Reply