Solved

php mysql_real_escape_string

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

822 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