Reply
error ! please help
Old 08-17-2007, 02:09 PM error ! please help
Experienced Talker

Posts: 30
Name: adam
Location: UK
i am creating a simple shoutbox which a user can submit a message and his/her name to a database then my messages.php calls the data up.

but in my main_code.php i seem to have a error. i want it so after a user has submitted their message and user name they get redirected back to the main page.

but it comes up with this error.

Fatal error: Call to undefined function redirect() in C:\wamp\www\MintuzProductions\ShoutboxLOUD\main_co de.php on line 16

the code i am using is as followed.

PHP Code:
<?php
if($_POST['submit']) {
$user=$_POST["name"];
$msg=$_POST["msg"];
//Make Sure a name has been submitted.
 
if(!(strlen(trim($user)))) $error[]="you must enter your nickname!";
//Make Sure a message has been posted.
 
if(!(strlen(trim($msg)))) $error[]="You must post a message!";
//Redirect to main page if the username & message has been filled in.
 
if($user='1'.$msg='1')
  
redirect('index.php','Your Message Has Been Posted');
   else 
redirect('index.php','You Did not post a message');
}
?>
also my shoutbox is actually using a inline frame.

i have index.php with the settings.php included though the include() function. then inside my index file i have an inline frame which links to the messages.php but at the same time inside my index file i also have the forms which uses the main_code.php to process the data.
mintuz is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 08-17-2007, 02:17 PM Re: error ! please help
Super Talker

Posts: 118
I've never heard of a built in redirect() function, but try this.

header ("Location: index.php");
__________________
flann
Free mortgage calculator
flann is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 09:49 PM Re: error ! please help
imagn's Avatar
Novice Talker

Posts: 9
Name: Matt
Location: Los Angeles
Right there isn't one...

Just load the message into a URL variable or store in memory if you want it "cleaner"
imagn is offline
Reply With Quote
View Public Profile Visit imagn's homepage!
 
Old 08-17-2007, 11:37 PM Re: error ! please help
goheadtry's Avatar
Webmaster Talker

Posts: 715
Name: John
Location: United States of America, California
There is no line 16 in ends at 15 with ?>
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 08-18-2007, 05:58 AM Re: error ! please help
intrinzic's Avatar
Novice Talker

Posts: 6
Name: Donna Maddox
Try this...
PHP Code:
<?php
if(isset($_POST['submit'])) {// check if form was submitted
    
$user=$_POST["name"];
    
$msg=$_POST["msg"];
    
//Make Sure name and msg is not empty
     
if(empty($_POST['name'])) {
     
$error="you must enter your nickname!";

     }elseif(empty(
$_POST['msg'])) {
     
$error="You must post a message!";
     }else{
    
    
$error="success";
     }
}
//end check if user have submitted the form

//Redirect to main page if the username & message has been filled in.
if($error == 'success'){
header ("Location: index.php");
}else{
header ("Location: index.php?error=$error");
}
?>
On your index.php place this code wherever you want the error to appear if there's error
PHP Code:
print "{$_GET['error']}"
intrinzic is offline
Reply With Quote
View Public Profile Visit intrinzic's homepage!
 
Old 08-18-2007, 06:56 AM Re: error ! please help
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
Nice clean helpful post there intrinzic!

and now for mine which probally wont be...

ok you could make the function to do that redirect if its a little easier.

PHP Code:
function redirect($pg$error_msg)
{
header("Location: $pg?error=$error_msg");

with the above if u have that included in the script you (should) be able to use the redirect() how you were

and the first part will be the page, and the second the error message.

you could also use:
PHP Code:
function redirect($pg$error_msg
{
if(!isset(
$error_msg)
{
header("Location: $pg");
}
else {
header("Location: $pg?error=$error_msg");
}

this second one is a bit more, the first ones a little more generic

This one, checks if you have enterd a second bit, so if u put
PHP Code:
redirect(index.php); 
it should look at it see it isnt set, and do a striaght redirect to that page using header("Location: $pg");

if it looks at it and see you have enterd soemthing else like:
PHP Code:
redirect(index.phperrorsomething when wrong); 
it should redirect to index.php?error=error! something when wrong

I have not tested this.

But i hope it helps,

Dan

Talkupation Apprieciated
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)

Last edited by dansgalaxy : 08-18-2007 at 06:58 AM.
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-18-2007, 08:42 AM Re: error ! please help
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
thanks, XD the TP just tipped me over the edge into the TOP TEN!! for TP hehe

Did the function work?
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-18-2007, 09:20 AM Re: error ! please help
Experienced Talker

Posts: 30
Name: adam
Location: UK
it did and didnt. because i am using a inline frame it seemed to of made like 500 different inline frames with in the same frame.
mintuz is offline
Reply With Quote
View Public Profile
 
Old 08-18-2007, 09:37 AM Re: error ! please help
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
Whaa? o.0

post link i wanna see wha you mean
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-18-2007, 10:12 AM Re: error ! please help
Experienced Talker

Posts: 30
Name: adam
Location: UK
i cant its on my localhost
mintuz is offline
Reply With Quote
View Public Profile
 
Old 08-18-2007, 10:42 AM Re: error ! please help
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
hehe im gonna ammed the function
PHP Code:
<?php
function redirect($pg$error_msg
#START FUNCTION

if(!isset($error_msg)
{
if(
headers_sent())
{
echo 
"<script type='text/javascript'>location.href='$pg';</script>";
}
else
{
header("Location: $pg");
}

}
else {
 
if(
headers_sent())
{
echo 
"<a script type='text/javascript'>location.href='$pg?error=$error_msg';</script>";
}
else {
header("Location: $pg?error=$error_msg");
}

}
}
# END FUNCTION  
?>
i think thats a bit better than before because it should stop any problems, if like any headers are sent it redirects with javascript.

hope it works, i just saw something in one of my scripts and was like yea!

__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to error ! please help
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16769 seconds with 12 queries