Solved

php mysql_real_escape_string

Posted on 2010-08-30
4
359 Views
Last Modified: 2012-06-21
I am using mysql_real_escape_string() for a variable before i put it into my db but for some reason it will not insert the value... it's just blank.

when I comment out the mysql_real_escape_string(variable) it inserts perfectly fine?
$test = $mvcfile->FileName;
$instrumental = mysql_real_escape_string($test);

mysql_query("INSERT INTO ORDERS 
(old_instrumental) VALUES('$instrumental') ") 
or die(mysql_error());

Open in new window

0
Comment
Question by:Solutionabc
4 Comments
 

Author Comment

by:Solutionabc
ID: 33563228
Even when I hard code $test = "please work"; it still inserts a blank feild.
0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33563229
You say when you comment the line out, by that do you also mean you update $instrumental in the SQL query to be $test? If not that could be the problem and you may need to do $instrumental = mysql_real_escape_string($instrumental); instead. (Without seeing any more of the code or the question above answering its difficult to tell.
0
 
LVL 15

Expert Comment

by:dave4dl
ID: 33563231
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 33563238
Couple of things:

Check what $test holds, use a var_dump which shows the var type and value at the same time.
When quoted variables don't work, I always resort to the good old concat.

$test = $mvcfile->FileName;
var_dump( $test );     /// dump the variable for debug
$instrumental = mysql_real_escape_string($test);
var_dump( $instrumental );     /// dump the variable for debug

$qry = "INSERT INTO ORDERS (old_instrumental) VALUES('" . $instrumental . "') ";
var_dump( $qry );     /// dump the variable for debug

mysql_query($qry)
or die(mysql_error());
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now