You are here: Re: correct syntax? « PHP SQL « IT news, forums, messages
Re: correct syntax?

Posted by Norman Peelman on 06/20/05 02:54

"Tony" <tony23.no@dslextreme.com.spam> wrote in message
news:11b47il500ieq16@corp.supernews.com...
> toedipper wrote:
> > Hello,
> >
> > Is this the right syntax for assigning a sql selct to a variable. When I
> > use this I get a parse error on the line that this is on.
> >
> > $thecustid = 'SELECT custid FROM customers WHERE userid =
> > $_SESSION['MM_Username']';
>
> No.
>
> You have a few problems. First of all, you are using single-quotes inside
a
> single-quoted string. Second, you can't include an array variable inside a
> string like that you'll have to use concatenation. Third, you aren't
> quoting the string content in the query - I expect this will likely cause
> problems on the SQL side.
>
> Try
> $thecustid = "SELECT custid FROM customers WHERE userid='" .
> $_SESSION['MM_Username'] . "'";
>

This also will work (previous example can get you lost in quotes and is hard
to read with uneccessary string concatination) :

$thecustid = "SELECT custid FROM customers WHERE userid=
$_SESSION[MM_Username]";

....when using array variables inside ".." you omit the '..' around the key
name.

Norm
--
FREE Avatar hosting at www.easyavatar.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация