Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php mysql_real_escape_string

Posted on 2010-08-30
4
Medium Priority
?
404 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

688 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