PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 4th, 2009, 06:18 PM
behnampmdg3's Avatar
behnampmdg3 behnampmdg3 is offline
hanibal hector
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2007
Posts: 537 behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 16 h 11 m 49 sec
Reputation Power: 63
$_POST echos wrong value

Hello;
I use this form to clean the form inputs and it works fine:
PHP Code:
function escape_string($data)
 {    
if(
is_array($data)) 
  {       
$ret = array();
foreach(
$data as $key=>$value)
      {
         
$ret[$key] = escape_string($value);
      }     
 return 
$ret;   
}   
else 
  {    
  if(!
is_numeric($data))  
    {         
 if(
get_magic_quotes_gpc())   
          {               
 
$data stripslashes($data); 
            }     
    
$data mysql_real_escape_string($data); 
         echo 
$test "Values so far:".$data
}     
 return 
$data;  
 } 
}  
// call clean function 
$clean_data escape_string($_POST); 

This part prints:
Values so far:\'\'\'
Which is correct. The magic quotes are off and the code does what it's supposed to do; adding slashes.

Now when I write the query later like this:
PHP Code:
echo $q="SELECT * FROM customers WHERE emailaddress  = '".$_POST['email']."'"

This prints :
SELECT * FROM customers WHERE emailaddress = '''''

What happened to the backslashes?????????????????

Reply With Quote
  #2  
Old November 4th, 2009, 07:47 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Dec 2004
Posts: 3,311 E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 19th Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 3 Weeks 1 Day 11 h 42 m 14 sec
Reputation Power: 2243
$_POST isn't passed as a reference to escape_string and you never assign the return value of escape_string back into $_POST (which is good practice anyway so you shouldn't change that). Your query should be using $clean_data instead of $_POST['email'].

Reply With Quote
  #3  
Old November 4th, 2009, 08:12 PM
behnampmdg3's Avatar
behnampmdg3 behnampmdg3 is offline
hanibal hector
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2007
Posts: 537 behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level)behnampmdg3 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 16 h 11 m 49 sec
Reputation Power: 63
Quote:
Originally Posted by E-Oreo
Your query should be using $clean_data instead of $_POST['email'].


Thanks, looks good

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > $_POST echos wrong value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek