Solved

php mysql_real_escape_string

Posted on 2010-08-30
4
385 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with PHP 13 27
PHP Curl to output a url 7 48
Accessing specific element - DOM PHP HTML 8 35
issue with DB import 1 19
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…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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.

830 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