LinuxSA Mailing list archives

Index: [thread] [date] [subject] [author] [stats]
  From: Andrew Halliday <andrew@recalldesign.com>
  To  : <linuxsa@linuxsa.org.au>
<james@adam.com.au> Date: Fri, 22 Jun 2001 15:27:02 +0930

Re: PHP question

Something like this general problem has happened to me before.  PHP gets
confused when attempting to expand two variables right next to each other.
If you put spaces between them it would have worked fine.  But of course,
you dont want spaces in a URL, so the way I get around it is a lot less
convaluted than other methods, and that is to make a base string and
concatenate them using the concatenate operator '.' eg:

$sql="INSERT INTO x (whatever,whatever) VALUES
(".$header.$whatever.",".$header.$whatever.");";

That works fine.  As to why this happens im not sure.  Maybe PHP parses
variables from the right to the left, and a resolved variable, when not
separated becomes concatenated with the variable name of the next variable
to make a new variable name that it doesnt recognize ... ? !

AndrewH

----- Original Message -----
From: "James Mclean" <james@adam.com.au>
To: <linuxsa@linuxsa.org.au>
Sent: Friday, June 22, 2001 12:16 PM
Subject: PHP question


>
>
> All,
>
> Does PHP only parse variables once? Reason I ask, see the script below...
>
> <?
>     if($save) {
>         $i=0;
>         while($i<$cols) {
>
>             $sql = "INSERT INTO latest (heading,text) VALUES
> ('\$header$i','\$text$i')";
>             print"$sql<br>";
>             //$qu = mysql_query($sql) or die(mysql_error());
>         $i++;
>         }
>
>             if(!mysql_error()) {
>                 print"<br>Latest News updated<br>";
>             } else {
>                 print" Dead. MySQL didnt like something";
>             }
>     }
> ?>
>
> In the INSERT statement, it constructs the variables, composed of the $i
for
> the interation, and the $header just as the name on the statement to be
> inserted. Variables are passed into the script with this generated URL...
>
> XXXXX.php?
>
header0=head+1&text0=body+2&header1=head+2+&text1=body+2&header2=head+3&text
2=bo
> dy+3&cols=3&save=Save+Paragraphs
>
> Now, the mysql_query is commented on purpose, and the $sql is echoed to
the
> screen, but it is not replacing the variables like it should.
> Q: Does PHP only parse variables Once??
> Q: If So, how do you get it to parse them more than once? I thought it did
that
> by default, perhaps not...
>
> This is the SQL output, generated by the parser, with 3 loops.
>
> INSERT INTO latest (heading,text) VALUES ('$header0','$text0')
> INSERT INTO latest (heading,text) VALUES ('$header1','$text1')
> INSERT INTO latest (heading,text) VALUES ('$header2','$text2')
>
> Should PHP then parse the $header0 and $text0??
>
> Cheers
>
> James Mclean
>
> --
> LinuxSA WWW: http://www.linuxsa.org.au/  IRC: #linuxsa on irc.linux.org.au
> To unsubscribe from the LinuxSA list:
>   mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject
>

-- 
LinuxSA WWW: http://www.linuxsa.org.au/  IRC: #linuxsa on irc.linux.org.au
To unsubscribe from the LinuxSA list:
  mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject


Index: [thread] [date] [subject] [author] [stats]
Return to the LinuxSA Mailing List Information Page