Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2012, 04:24 AM   PM User | #1
jryan54
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
jryan54 is an unknown quantity at this point
Validating Data with a conditional

Hey guys,

Pretty brand new to PHP so learning as I go.

I've got a web form which posts to a file called signup.php. Now within this file i'm trying to take a post variable $_POST[name] and see if its actually empty.

I have an if loop in place to check BUT no matter what I do it doesnt seem to fire. It def has something to do with the code below it because it works when I remove that code.

Anyway, any ideas?

P.S I know its horrible code but im slowly learning bit by bit.

Code:
if ( ! empty($_POST['name']))
 	{  
        
    }
	else
	{
	 header('Location:signup.php');
     }
	 
	 

// escape user input

$_POST[name] = mysql_real_escape_string($_POST[name]);
$_POST[email] = mysql_real_escape_string($_POST[email]);
$_POST[company] = mysql_real_escape_string($_POST[company]);
$_POST[country] = mysql_real_escape_string($_POST[country]);
$_POST[password] = mysql_real_escape_string($_POST[password]);

// Encrypt the password using MD5

$_POST[password] = md5($_POST[password]);

// store client ip address to variable
$ip = $_SERVER['REMOTE_ADDR'];   

// Insert sanitized POST data into the mysql database

$sql="INSERT INTO sellers (name, email, company_name, country, password, ip_address)
VALUES
('$_POST[name]','$_POST[email]','$_POST[company]','$_POST[country]','$_POST[password]','$_POST[ip]')";

if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}


header('Location:signupsuccess.php');
jryan54 is offline   Reply With Quote
Old 12-03-2012, 04:34 AM   PM User | #2
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 892
Thanks: 4
Thanked 206 Times in 205 Posts
tracknut is an unknown quantity at this point
At a minimum, you're missing all the quotes in the post array references...
Code:
$_POST['name'] = mysql_real_escape_string($_POST['name']);
tracknut is online now   Reply With Quote
Users who have thanked tracknut for this post:
jryan54 (12-03-2012)
Old 12-03-2012, 05:58 AM   PM User | #3
jryan54
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
jryan54 is an unknown quantity at this point
Thanks for that...okay i've added in the quotes....obviously still no effect upon my IF statement.

So clearly something still going on.

Anyone? bueller bueller?
jryan54 is offline   Reply With Quote
Old 12-03-2012, 12:14 PM   PM User | #4
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
PHP Code:
if (empty($_POST['name'])) {header('Location:signup.php');} 
Based on what you had in the original post it looks like you want to go to the signup page if the name field on the form is blank.
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:04 AM.


Advertisement
Log in to turn off these ads.