Current location: Hot Scripts Forums » Programming Languages » PHP » What is wrong with this?


What is wrong with this?

Reply
  #1 (permalink)  
Old 10-05-06, 06:34 AM
silvercover's Avatar
silvercover silvercover is offline
Wannabe Coder
 
Join Date: Aug 2004
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
What is wrong with this?

Hi:

I have a php code as follows:

PHP Code:

<?php


/////////////////////////////////Begin Registration///////////////////////////
// Validate users input
if(!empty($_POST))
{
    
// Check email is a valid email address
    
if(isset($_POST['email'])) if(!ereg("^([a-zA-Z0-9_\.\-]+)@((\[[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,}|[0-9]{1,})(\]?)$"$_POST['email'])) $eg_error['email'] = "Invalid email";
    
// Check email has a value
    
if(empty($_POST['email'])) $eg_error['email'] = "Enter email";
    
// Check nickname has a value
    
if(empty($_POST['nickname'])) $eg_error['nickname'] = "Enter nickname";
    
// Check fname has a value
    
if(empty($_POST['fname'])) $eg_error['fname'] = "Enter first";
    
// Check lname has a value
    
if(empty($_POST['lname'])) $eg_error['lname'] = "Enter last name";
    
// Check confirm_email has a value
    
if(empty($_POST['confirm_email'])) $eg_error['confirm_email'] = "confirm email";
    
// Check project_name has a value
    
if(empty($_POST['project_name'])) $eg_error['project_name'] = "Enter project name";
    
// Check confirm_email is a valid email address
    
if(isset($_POST['confirm_email'])) if(!ereg("^([a-zA-Z0-9_\.\-]+)@((\[[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,}|[0-9]{1,})(\]?)$"$_POST['confirm_email'])) $eg_error['confirm_email'] = "Invalid email";
    
// Check if any errors were returned and run relevant code
    
if(empty($eg_error))
    {
        
// Conditional statement
        
if(@$_POST['email'] != @$_POST['confirm_email'])
        {
            
$ecom "entered email addresses did not match";
        }
        else
        {
            
$eg_text_2 "[f] [l]";
            
$eg_text_2 str_replace("[f]", @$_POST['fname'], $eg_text_2);
            
$eg_text_2 str_replace("[l]", @$_POST['lname'], $eg_text_2);
            
$eg_text_1 "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n<title></title>\n</head>\n<body>\n<p align=\"center\"><b><font size=\"5\" color=\"#000080\">New Registration Request</font></b></p>\n<hr size=\"1\">\n<table border=\"0\" width=\"100%\" id=\"table1\">\n    <tr>\n        <td width=\"25%\" align=\"right\"><font color=\"#800000\"><b>Nickname :</b></font></td>\n        <td>{nick_name}</td>\n    </tr>\n    <tr>\n        <td width=\"25%\" align=\"right\"><font color=\"#800000\"><b>Full Name :</b></font></td>\n        <td>{full_name}</td>\n    </tr>\n    <tr>\n        <td width=\"25%\" align=\"right\"><font color=\"#800000\"><b>Email :</b></font></td>\n        <td>{email}</td>\n    </tr>\n    <tr>\n        <td width=\"25%\" align=\"right\"><font color=\"#800000\"><b>Project Name :</b></font></td>\n        <td>{project_name}</td>\n    </tr>\n    <tr>\n        <td width=\"25%\" align=\"right\"><font color=\"#800000\"><b>IP Address :</b></font></td>\n        <td><?=$_SERVER[REMOTE_ADDR]?></td>\n    </tr>\n</table>\n</body>\n</html>";
            
$eg_text_1 str_replace("{nick_name}", @$_POST['nickname'], $eg_text_1);
            
$eg_text_1 str_replace("{full_name}"$eg_text_2$eg_text_1);
            
$eg_text_1 str_replace("{email}", @$_POST['email'], $eg_text_1);
            
$eg_text_1 str_replace("{project_name}", @$_POST['project_name'], $eg_text_1);
            
// Check required values have been passed to email
            
if(!empty($_POST['email']))
            {
                
// Send email
                
mail("mail@site.com""New Registration Request"$eg_text_1"From: ".@$_POST['email']."\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\n");
                
            }
            
$eg_text_3 "Dear {nam}\n\nThank you for your registration. We will response as soon as possible.\nif you have comment or question, you can send it from here:\n\nhttp://www.site.com/contest/contactus.php\n\nRegards\n--------------------------------\nMMB Contest 2006 Team";
            
$eg_text_3 str_replace("{nam}"$eg_text_2$eg_text_3);
            
// Check required values have been passed to email
            
if(!empty($_POST['email']))
            {
                
// Send email
                
mail(@$_POST['email'], "Thank you for your MMB contest registration"$eg_text_3"From: mail@site.com\r\n");
                
            }
            
// Go to page
            
header("Location: registration_success.php");
            exit;
        }
    }
}
/////////////////////////////////End Registration///////////////////////////
It works ok until it wants to redirect user to registration success page. instead of showing that page i get blank page!

what is wrong with header() function?

Thanks in advance.

Last edited by nico_swd; 10-05-06 at 06:48 AM. Reason: Please use [php] wrappers when posting PHP code.
Reply With Quote
  #2 (permalink)  
Old 10-05-06, 08:13 AM
techie-blogs.com's Avatar
techie-blogs.com techie-blogs.com is offline
New Member
 
Join Date: Oct 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Silvercover,

Your header function call looks fine to me. What happens if you hit registration_success.php directly?

You can also use curl to test the redirection, etc:

curl -D- http://.....

The curl option -L will follow location headers, but try without it first.
Reply With Quote
  #3 (permalink)  
Old 10-05-06, 08:27 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
It is highly likely that your code is outputting something to the browser prior to the header(...) statement which will prevent the header from being sent to the browser. Add the following line of code after your opening <?php tag and see if there are any errors reported -
PHP Code:

error_reporting(E_ALL); 

__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #4 (permalink)  
Old 10-05-06, 02:48 PM
silvercover's Avatar
silvercover silvercover is offline
Wannabe Coder
 
Join Date: Aug 2004
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks mab for your reply. I did as you said and got this info:

Warning: Cannot modify header information - headers already sent by (output started at /home/parsianp/public_html/contest_2006/index.php:1) in /home/parsianp/public_html/contest_2006/index.php on line 58

Question:

Can Encoding issues be cuase of my problem?

Last edited by silvercover; 10-05-06 at 03:01 PM.
Reply With Quote
  #5 (permalink)  
Old 10-05-06, 02:56 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
I suspect that there is a newline or a space before the opening <. Check to make sure that it is the first thing in the file.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #6 (permalink)  
Old 10-05-06, 03:04 PM
silvercover's Avatar
silvercover silvercover is offline
Wannabe Coder
 
Join Date: Aug 2004
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
I checked. There is no such line and space!
Reply With Quote
  #7 (permalink)  
Old 10-05-06, 03:12 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
If this is shared hosting, your hosting company may be outputting something to the browser prior to the start of your code.

Here is plan B, replace the header(....); line with the following -
PHP Code:

echo "<meta http-equiv=\"refresh\" content=\"0;url=registration_success.php\">"
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #8 (permalink)  
Old 10-05-06, 03:27 PM
silvercover's Avatar
silvercover silvercover is offline
Wannabe Coder
 
Join Date: Aug 2004
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks mab. Finally it works!!
A BIG THANKS.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning: Wrong parameter count... Tim Mousel PHP 5 01-23-06 12:10 PM
CSS: what's wrong with this? jasperma CSS 1 12-11-04 07:44 PM
Whats wrong with this query? FiRe PHP 5 11-07-04 10:26 AM
what am i doing wrong? CrAzY_CuStoMs PHP 5 11-01-04 11:42 PM
What is wrong with this script donkon PHP 3 10-28-04 02:36 AM


All times are GMT -5. The time now is 05:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.