Solved

php mysql_real_escape_string

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
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…
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 …

710 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