PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Complex escape string
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Complex escape string

Réponse
 
LinkBack Outils de la discussion
Vieux 03/05/2008, 18h20   #1
cyaugin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Complex escape string

I have this line of code:

$q = "This is the string that will go into the query:
{${mysql_real_escape_string($_GET['searchstring'])}}";

What happens then is the user supplies 'foo' as the search string, and I get
a debug notice "Undefined variable: foo". Why is it treating the value as an
identifier and how do I make it do what I actually want it to do? This is on
PHP5, latest release.


  Réponse avec citation
Vieux 03/05/2008, 18h36   #2
Casey
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Complex escape string

On 5/3/08, cyaugin <cyaugin@yahoo.com> wrote:
> I have this line of code:
>
> $q = "This is the string that will go into the query:
> {${mysql_real_escape_string($_GET['searchstring'])}}";
>
> What happens then is the user supplies 'foo' as the search string, and I get
> a debug notice "Undefined variable: foo". Why is it treating the value as an
> identifier and how do I make it do what I actually want it to do? This is on
> PHP5, latest release.
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

$q = "This is the string that will go into the query: " .
mysql_real_escape_string($_GET['searchstring']);

--
-Casey
  Réponse avec citation
Vieux 03/05/2008, 19h52   #3
Craige Leeder
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Complex escape string

Why exactly are you doing this? While variable-variables can be of use
at times, I don't think this is one of them. How do you use this newly
created variable.

- Craige

On Sat, May 3, 2008 at 1:20 PM, cyaugin <cyaugin@yahoo.com> wrote:
> I have this line of code:
>
> $q = "This is the string that will go into the query:
> {${mysql_real_escape_string($_GET['searchstring'])}}";
>
> What happens then is the user supplies 'foo' as the search string, and I get
> a debug notice "Undefined variable: foo". Why is it treating the value as an
> identifier and how do I make it do what I actually want it to do? This is on
> PHP5, latest release.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

  Réponse avec citation
Vieux 03/05/2008, 20h30   #4
Steven R. Ringwald
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] Complex escape string

-----Original Message-----
From: cyaugin [mailto:cyaugin@yahoo.com]
Sent: Saturday, May 03, 2008 10:20 AM
To: php-general@lists.php.net
Subject: [php] Complex escape string

I have this line of code:

$q = "This is the string that will go into the query:
{${mysql_real_escape_string($_GET['searchstring'])}}";

What happens then is the user supplies 'foo' as the search string, and I get
a debug notice "Undefined variable: foo". Why is it treating the value as an
identifier and how do I make it do what I actually want it to do? This is on
PHP5, latest release.




---------------

It looks to me like what is happening is this piece:
${mysql_real_escape_string($_GET['searchstring'])}

Gets collapsed to $foo when mysql_real_escape_string($_GET['searchstring'])
== 'foo'. ${'a'} will expand to $a. I think that your problem is that you
need to drop that '$' before the brace around the function call.




  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h15.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09248 seconds with 12 queries