Current location: Hot Scripts Forums » Programming Languages » PHP » when error moving code in array

when error moving code in array

Reply
  #1 (permalink)  
Old 07-10-09, 09:07 AM
zodehala zodehala is offline
Wannabe Coder
 
Join Date: Mar 2007
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
when error moving code in array

PHP Code:

if ($_POST) {
    if (!empty(
$_POST['name'])) 
    {
    
//codes
        
echo $_POST['name'].'<br />';
    } else 
        
$eror[]="error message";    
        if (
preg_match('$regex',$_POST['email'])) 
        {
            
// codes 
            
echo $_POST['email'];
        } else 
$eror[]="error message";

when error occured how will we assign mesages into array and automatically wil send array to y.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-10-09, 10:16 AM
Nico's Avatar
Nico Nico is online now
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,535
Thanks: 5
Thanked 17 Times in 16 Posts
Take a deeper look at your script's flow/logic, and think about what it does.

The email is only being validated if the "name" is empty. Meaning, if the user enters a name, the email won't be validated at all.

And on another note, there shouldn't be quotes around the $regex variable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-12-09, 01:27 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,651
Thanks: 0
Thanked 21 Times in 21 Posts
PHP Code:
<?php
$regex 
'/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i';
if(
$_POST)
{
 if(!empty(
$_POST['name']))
 {
  
//codes
  
$name $_POST['name'];
  }
 else
 {
  
$error[]="You must enter your name.";
  }
 if(
preg_match($regex,$_POST['email']))
 {
  
// codes
  
$email $_POST['email'];
  }
 else
 {
  
$error[]="You did not supply a valid email address.";
  }
 
$error_msg = empty($error) ? "" implode(',',$error);
 
header("location:y.php?name=$name&email=$email&error=$error_msg");
 }
?>
y.php
PHP Code:
<?php
if(!empty($_GET["error"]))
{
 
$errors explode(",",$_GET["error"]);
 for(
$i=0;$i<count($errors);$i++)
 {
  echo 
$errors[$i]."<br />";
  }
 }
$name = empty($_GET["name"])?"&nbsp;":$_GET["name"];
$email = empty($_GET["email"])?"&nbsp;":$_GET["email"];
echo 
"<table border='1'>
       <tr><th>Name</th><th>Email</th></tr>
       <tr><td align='center'>$name</td><td align='center'>$email</td></tr><tr>
      </table> "
;
?>
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
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
Need captcha for html+php contact form sujata_ghosh PHP 6 03-22-09 04:46 PM
PHP inside JavaScript? pikaz JavaScript 14 07-17-07 08:05 AM
How to select a transaction of an array and check it on regular basis Oskare100 PHP 0 12-28-06 06:27 PM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 01:10 PM
linking to iframe not working :( j0d JavaScript 5 01-19-04 09:14 PM


All times are GMT -5. The time now is 07:40 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.