473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

quote smart fails with null string

from: http://us3.php.net/mysql_real_escape_string

// Quote variable to make safe
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not a number or a numeric string
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}

However when I pass it a null string it returns just a single
double quote.
It would be easy to fix, but I don't understand why it does this.

bill
Dec 23 '06 #1
2 2231
bill schreef:
from: http://us3.php.net/mysql_real_escape_string

// Quote variable to make safe
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not a number or a numeric string
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}

However when I pass it a null string it returns just a single double quote.
It would be easy to fix, but I don't understand why it does this.
All mysql_real_escape_string does is replace characters... Since php
will replace NULL with an empty string, the mysql_real_escape_string
returns an empty string.. .So value becomes the concatenation of ',
empty string and '.

I think your confusion comes from the fact that $value = "NULL" and
$value = null both mean different things.... And on top of that in a SQL
query "NULL" and NULL mean different things too....

--
Tim Van Wassenhove <url:http://www.timvw.be/>
Dec 23 '06 #2
Tim Van Wassenhove wrote:
bill schreef:
>from: http://us3.php.net/mysql_real_escape_string

// Quote variable to make safe
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not a number or a numeric string
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}

However when I pass it a null string it returns just a single double
quote.
It would be easy to fix, but I don't understand why it does this.

All mysql_real_escape_string does is replace characters... Since php
will replace NULL with an empty string, the mysql_real_escape_string
returns an empty string.. .So value becomes the concatenation of ',
empty string and '.

I think your confusion comes from the fact that $value = "NULL" and
$value = null both mean different things.... And on top of that in a SQL
query "NULL" and NULL mean different things too....
Actually, my eyes were failing. I read '' as ". It was working
fine.

bill
Dec 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vishwanathan Raman | last post by:
I am trying to deploy my Smart Client (it accesses a Web Service) on to a server.It works fine in my machine and also works when others access it from my machine But when deployed to another server...
6
by: Johnny Hansen | last post by:
Hello, I've been trying to implement smart pointers in C++ (combined with a reference counter) because I want to do some memory management. My code is based on the gamedev enginuity articles,...
27
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined...
0
by: lglmi | last post by:
'********************START OF BAS MODULE******************** Option Explicit Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long...
2
by: Erik | last post by:
I'm trying to get the login name for the user, and this is the code I use: string userName = WindowsIdentity.GetCurrent().Name; This works fine when the program is launched locally or...
10
by: RodBillett | last post by:
Using SmartNavigation. Windows2003 Server Framework 1.0 (3705) IIS6 and I have IIS configured to utilize the 1.0 framework. Any Ideas why I would be getting the following jscript error within...
1
by: Venkat Kasaram | last post by:
Hi I am working with Smart Client.I am having a windows application which needs to works with Multiple Languages so i am using Sattilitie assemblies. It is working fine if run the apllication...
2
by: Serman D. | last post by:
Hi all, I'm trying to complete the samples from the excellent 2003 developerWorks article "Bringing the Power of Regular Expression Matching to SQL" by Knut Stolze: http://tinyurl.com/3bhrnn...
9
by: D1R | last post by:
I have to migrate a web application written in PHP and I am using PHP 5.2.6 ISAPI. The problem I have is related to some sql queries that have the following format: $sql = "insert into...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.