pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PHP calling PHP?
17+ messages / 7 participants
[nested] [flat]

* PHP calling PHP?
@ 2001-05-05 12:51  Christian Marschalek <cm@chello.at>
  0 siblings, 1 reply; 17+ messages in thread

From: Christian Marschalek @ 2001-05-05 12:51 UTC (permalink / raw)
  To: pgsql-php

Hi!

Let's say I want to insert some data into my db and I want to be sure
that the user fills out alle the requiered fields. 

I'm thinking of that: I want to pass the data to a PHP script and if
there's something missing I want to call the input PHP script again but
this time with the already inserted data. I can I call a link inside a
PHP script without having the user to click on it?

Tia Chris




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-05 13:32  Gyozo Papp <pgerzson@freestart.hu>
  parent: Christian Marschalek <cm@chello.at>
  0 siblings, 1 reply; 17+ messages in thread

From: Gyozo Papp @ 2001-05-05 13:32 UTC (permalink / raw)
  To: Christian Marschalek <cm@chello.at>; pgsql-php


if (! $ok )
{
    // register your variables with the current session
    // in order that you are able to use it in the other page (fillin.php)
    Header("Location: fillin.php");
    exit;
}

see header() function in the manual!
and I

----- Original Message ----- 
From: "Christian Marschalek" <cm@chello.at>
To: "[PHP] PostgreSQL" <pgsql-php@postgresql.org>
Sent: 2001. május 5. 14:51
Subject: [PHP] PHP calling PHP?


> Hi!
> 
> Let's say I want to insert some data into my db and I want to be sure
> that the user fills out alle the requiered fields. 
> 
> I'm thinking of that: I want to pass the data to a PHP script and if
> there's something missing I want to call the input PHP script again but
> this time with the already inserted data. I can I call a link inside a
> PHP script without having the user to click on it?
> 
> Tia Chris
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* RE: PHP calling PHP?
@ 2001-05-05 15:40  Christian Marschalek <cm@chello.at>
  parent: Gyozo Papp <pgerzson@freestart.hu>
  0 siblings, 1 reply; 17+ messages in thread

From: Christian Marschalek @ 2001-05-05 15:40 UTC (permalink / raw)
  To: 'Gyozo Papp' <pgerzson@freestart.hu>; +Cc: pgsql-php

That's excatly what I needed :)

Thanks.

Another one:

If I have a html form an in it a text field with the a name like this:
name="foo*bar"
How would I refer to it in my php script? Normaly variable names have no
* in them, do they?:)

Chris

> -----Original Message-----
> From: Gyozo Papp [mailto:pgerzson@freestart.hu] 
> Sent: Saturday, May 05, 2001 3:33 PM
> To: Christian Marschalek; [PHP] PostgreSQL
> Subject: Re: [PHP] PHP calling PHP?
> 
> 
> 
> if (! $ok )
> {
>     // register your variables with the current session
>     // in order that you are able to use it in the other page 
> (fillin.php)
>     Header("Location: fillin.php");
>     exit;
> }
> 
> see header() function in the manual!
> and I
> 
> ----- Original Message ----- 
> From: "Christian Marschalek" <cm@chello.at>
> To: "[PHP] PostgreSQL" <pgsql-php@postgresql.org>
> Sent: 2001. május 5. 14:51
> Subject: [PHP] PHP calling PHP?
> 
> 
> > Hi!
> > 
> > Let's say I want to insert some data into my db and I want 
> to be sure 
> > that the user fills out alle the requiered fields.
> > 
> > I'm thinking of that: I want to pass the data to a PHP 
> script and if 
> > there's something missing I want to call the input PHP script again 
> > but this time with the already inserted data. I can I call a link 
> > inside a PHP script without having the user to click on it?
> > 
> > Tia Chris
> > 
> > 
> > ---------------------------(end of 
> > broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> 




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-05 16:09  Gyozo Papp <pgerzson@freestart.hu>
  parent: Christian Marschalek <cm@chello.at>
  0 siblings, 1 reply; 17+ messages in thread

From: Gyozo Papp @ 2001-05-05 16:09 UTC (permalink / raw)
  To: Christian Marschalek <cm@chello.at>; +Cc: pgsql-php

Hello,

your last question is more than interesting. 
You can try the code below and just look what is happening!

Seriously, If you use either $HTTP_POST_VARS or $HTTP_GET_VARS (respect to the action)
1: you can access the variable with its original name ($HTTP_POST_VARS['foo*bar'], in my example), 
2: but you can't refer to it as a common global variable like : $foo*bar. 
3: much more interesting with variable variables, try and see. I don't say annything ... :)

<?php
var_dump($HTTP_POST_VARS['foo*bar']); // example for 1
var_dump($foo*bar); // syntax error: constant bar is not defined
$var= 'foo*bar'; 
var_dump($$var); //work around with variable variables
?>
<form method=post action="<? echo $PHP_SELF ?>">
<input type="text" name="foo*bar" value='a'>
<input type="submit">
</form>

----- Original Message ----- 
From: "Christian Marschalek" <cm@chello.at>
To: "'Gyozo Papp'" <pgerzson@freestart.hu>
Cc: "[PHP] PostgreSQL" <pgsql-php@postgresql.org>
Sent: 2001. május 5. 17:40
Subject: RE: [PHP] PHP calling PHP?


That's excatly what I needed :)

Thanks.

Another one:

If I have a html form an in it a text field with the a name like this:
name="foo*bar"
How would I refer to it in my php script? Normaly variable names have no
* in them, do they?:)

Chris

> -----Original Message-----
> From: Gyozo Papp [mailto:pgerzson@freestart.hu] 
> Sent: Saturday, May 05, 2001 3:33 PM
> To: Christian Marschalek; [PHP] PostgreSQL
> Subject: Re: [PHP] PHP calling PHP?
> 
> 
> 
> if (! $ok )
> {
>     // register your variables with the current session
>     // in order that you are able to use it in the other page 
> (fillin.php)
>     Header("Location: fillin.php");
>     exit;
> }
> 
> see header() function in the manual!
> and I
> 
> ----- Original Message ----- 
> From: "Christian Marschalek" <cm@chello.at>
> To: "[PHP] PostgreSQL" <pgsql-php@postgresql.org>
> Sent: 2001. május 5. 14:51
> Subject: [PHP] PHP calling PHP?
> 
> 
> > Hi!
> > 
> > Let's say I want to insert some data into my db and I want 
> to be sure 
> > that the user fills out alle the requiered fields.
> > 
> > I'm thinking of that: I want to pass the data to a PHP 
> script and if 
> > there's something missing I want to call the input PHP script again 
> > but this time with the already inserted data. I can I call a link 
> > inside a PHP script without having the user to click on it?
> > 
> > Tia Chris
> > 
> > 
> > ---------------------------(end of 
> > broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> 





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-08 04:04  Steve Werby <steve-lists@befriend.com>
  parent: Gyozo Papp <pgerzson@freestart.hu>
  0 siblings, 1 reply; 17+ messages in thread

From: Steve Werby @ 2001-05-08 04:04 UTC (permalink / raw)
  To: Gyozo Papp <pgerzson@freestart.hu>; Christian Marschalek <cm@chello.at>; +Cc: pgsql-php

"Gyozo Papp" <pgerzson@freestart.hu> wrote:
> Seriously, If you use either $HTTP_POST_VARS or $HTTP_GET_VARS (respect to
the action)
> 1: you can access the variable with its original name
($HTTP_POST_VARS['foo*bar'], in my example),
> 2: but you can't refer to it as a common global variable like : $foo*bar.
> 3: much more interesting with variable variables, try and see. I don't say
annything ... :)

Also, variables cannot have numbers in their name, but a variable variables
workaround allows them to be used.  For example:

You cannot set $1 = "something".

But you can do:

$a = 1;
$$a = "something";
echo $$a; // prints "something".

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-08 04:19  Grant <grant@conprojan.com.au>
  parent: Steve Werby <steve-lists@befriend.com>
  0 siblings, 2 replies; 17+ messages in thread

From: Grant @ 2001-05-08 04:19 UTC (permalink / raw)
  To: pgsql-php

> Also, variables cannot have numbers in their name, but a variable variables
> workaround allows them to be used.  For example:

Wrong.




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-08 04:34  Chris Smith <csmith@squiz.net>
  parent: Grant <grant@conprojan.com.au>
  1 sibling, 2 replies; 17+ messages in thread

From: Chris Smith @ 2001-05-08 04:34 UTC (permalink / raw)
  To: Grant <grant@conprojan.com.au>; pgsql-php


> > Also, variables cannot have numbers in their name, but a variable
> > variables workaround allows them to be used.  For example:
>
> Wrong.

That's helpful. Why? Example?



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-08 04:42  Grant <grant@conprojan.com.au>
  parent: Chris Smith <csmith@squiz.net>
  1 sibling, 0 replies; 17+ messages in thread

From: Grant @ 2001-05-08 04:42 UTC (permalink / raw)
  To: pgsql-php

> > Wrong.
> 
> That's helpful. Why? Example?

Thanks for the copy but I already get the message because I'm on
the email list.

~# cat test
#!/usr/local/bin/php -q
<?php
$variable_with_a_number_1_in_it = "Test";
echo "$variable_with_a_number_1_in_it\n";
?>
~# ./test
Test
~#




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-08 05:16  Mitch Vincent <mitch@venux.net>
  parent: Chris Smith <csmith@squiz.net>
  1 sibling, 0 replies; 17+ messages in thread

From: Mitch Vincent @ 2001-05-08 05:16 UTC (permalink / raw)
  To: Chris Smith <csmith@squiz.net>; Grant <grant@conprojan.com.au>; pgsql-php

And furthermore..

"Variable names follow the same rules as other labels in PHP. A valid
variable name starts with a letter or underscore, followed by any number of
letters, numbers, or underscores. As a regular expression, it would be
expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' "

From the PHP manual -- http://www.php.net/manual/en/language.variables.php

Note that variables can't *start* with a number but can contain numbers
after the first character..

-Mitch

----- Original Message -----
From: "Chris Smith" <csmith@squiz.net>
To: "Grant" <grant@conprojan.com.au>; <pgsql-php@postgresql.org>
Sent: Tuesday, May 08, 2001 12:34 AM
Subject: Re: [PHP] PHP calling PHP?


>
> > > Also, variables cannot have numbers in their name, but a variable
> > > variables workaround allows them to be used.  For example:
> >
> > Wrong.
>
> That's helpful. Why? Example?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-10 04:36  Steve Werby <steve-lists@befriend.com>
  parent: Grant <grant@conprojan.com.au>
  1 sibling, 1 reply; 17+ messages in thread

From: Steve Werby @ 2001-05-10 04:36 UTC (permalink / raw)
  To: pgsql-php

"Grant" <grant@conprojan.com.au> wrote:
> > Also, variables cannot have numbers in their name, but a variable
variables
> > workaround allows them to be used.  For example:
>
> Wrong.

You cut out my example which demonstrated a way to use variable variables to
access a variable name consisting solely of a number.  Though I did say
variables cannot have numbers in their name, I really meant that they cannot
consist solely of numbers.  The reason I made the point and posted the
example was b/c I've seen programmers who wanted to apply numeric variable
names from within a loop and this workaround allows this to be done.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-10 04:54  Grant <grant@conprojan.com.au>
  parent: Steve Werby <steve-lists@befriend.com>
  0 siblings, 1 reply; 17+ messages in thread

From: Grant @ 2001-05-10 04:54 UTC (permalink / raw)
  To: Steve Werby <steve-lists@befriend.com>; +Cc: pgsql-php

> You cut out my example which demonstrated a way to use variable variables to
> access a variable name consisting solely of a number.  Though I did say
> variables cannot have numbers in their name, I really meant that they cannot
> consist solely of numbers.  The reason I made the point and posted the
> example was b/c I've seen programmers who wanted to apply numeric variable
> names from within a loop and this workaround allows this to be done.

Sorry dude, but yes! Variables inside variables are very elite.

For instance:

Question: "Please help, I'd like dynamic field names, how can I do this?!"

<HTML>
<BODY>

<?

if (isset($username)):

echo "Username is <B>" . $$username . "</B><BR>\n";
echo "Password is <B>" . $$password . "</B><BR><BR>\n";
echo "<A HREF=$PHP_SELF>Back</A>\n";

else:

$time = date("U");
echo "<FORM ACTION=\"$PHP_SELF\" METHOD=\"POST\">\n";
echo "Username: <INPUT
TYPE=\"TEXT\" NAME=\"$time" . "_u\" AUTOCOMPLETE=\"OFF\"><BR>\n";
echo "Password: <INPUT TYPE=\"PASSWORD\" NAME=\"$time" . "_p\"><BR>\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"username\" VALUE=\"$time" . "_u\">\n";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"password\" VALUE=\"$time" . "_p\">\n";
echo "<INPUT TYPE=\"SUBMIT\" NAME=\"Submit\" VALUE=\"Submit\">\n";

endif;

?>

</FORM>

</BODY>
</HTML>




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-10 05:03  Roberto Mello <rmello@cc.usu.edu>
  parent: Grant <grant@conprojan.com.au>
  0 siblings, 1 reply; 17+ messages in thread

From: Roberto Mello @ 2001-05-10 05:03 UTC (permalink / raw)
  To: Grant <grant@conprojan.com.au>; +Cc: Steve Werby <steve-lists@befriend.com>; pgsql-php

On Thu, May 10, 2001 at 02:54:58PM +1000, Grant wrote:
> 
> echo "Username is <B>" . $$username . "</B><BR>\n";
> echo "Password is <B>" . $$password . "</B><BR><BR>\n";

	Weird. When I tried using "$$varname" it wouldn't work, so I resorted
to un ugly use of eval to do the trick. I'll have to try again sometime.

> $time = date("U");
> echo "<FORM ACTION=\"$PHP_SELF\" METHOD=\"POST\">\n";

	Ack! You could do this for much better readability instead:

	echo "<FORM ACTION='$PHP_SELF' METHOD='POST'>\n";

	-Roberto
-- 
+----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+
  Roberto Mello - Computer Science, USU - http://www.brasileiro.net 
       http://www.sdl.usu.edu - Space Dynamics Lab, Developer    
The pizza at the neigbors table has always MORE chesse.



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-10 05:10  Grant <grant@conprojan.com.au>
  parent: Roberto Mello <rmello@cc.usu.edu>
  0 siblings, 1 reply; 17+ messages in thread

From: Grant @ 2001-05-10 05:10 UTC (permalink / raw)
  To: pgsql-php

> > echo "<FORM ACTION=\"$PHP_SELF\" METHOD=\"POST\">\n";
> 
> 	Ack! You could do this for much better readability instead:

Yes! Hehe, I have a complex with escaping quotes.




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-10 05:23  Chris Smith <csmith@squiz.net>
  parent: Grant <grant@conprojan.com.au>
  0 siblings, 3 replies; 17+ messages in thread

From: Chris Smith @ 2001-05-10 05:23 UTC (permalink / raw)
  To: pgsql-php


> > > echo "<FORM ACTION=\"$PHP_SELF\" METHOD=\"POST\">\n";
> >
> > 	Ack! You could do this for much better readability instead:
> > echo "<FORM ACTION='$PHP_SELF' METHOD='POST'>\n";

Different quotes do different things in PHP, just something to remember...

If you did echo '$PHP_SELF' (single quotes) it won't print the variable 
value, it will print the variable name.. (easy to get caught on!)..

eg
<?
        echo "PHPSELF = $PHP_SELF<br>";
        echo 'PHPSELF = $PHP_SELF<br>';
?>

prints out..

PHPSELF = test.php
PHPSELF = $PHP_SELF



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* RE: PHP calling PHP?
@ 2001-05-10 05:32  Christian Marschalek <cm@chello.at>
  parent: Chris Smith <csmith@squiz.net>
  2 siblings, 0 replies; 17+ messages in thread

From: Christian Marschalek @ 2001-05-10 05:32 UTC (permalink / raw)
  To: 'Chris Smith' <csmith@squiz.net>; +Cc: pgsql-php

> If you did echo '$PHP_SELF' (single quotes) it won't print 
> the variable value, it will print the variable name.. (easy to get
caught on!)..
Well, what did you know... You always learn something new ;)

I realy like this list;)





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-10 15:54  Steve Werby <steve-lists@befriend.com>
  parent: Chris Smith <csmith@squiz.net>
  2 siblings, 0 replies; 17+ messages in thread

From: Steve Werby @ 2001-05-10 15:54 UTC (permalink / raw)
  To: pgsql-php

"Chris Smith" <csmith@squiz.net> wrote:
> If you did echo '$PHP_SELF' (single quotes) it won't print the variable
> value, it will print the variable name.. (easy to get caught on!)..
>
> eg
> <?
>         echo "PHPSELF = $PHP_SELF<br>";
>         echo 'PHPSELF = $PHP_SELF<br>';
> ?>
>
> prints out..
>
> PHPSELF = test.php
> PHPSELF = $PHP_SELF

That's called interpolation.  Variables within double quotes are
interpolated (converted to their corresponding values), while variables
within single quotes are not.  This really isn't emphasized enough in the
PHP manual and presents a lot of problems for PHP newbies who aren't
familiar with this behavior and are struggling to find the best way to
handle quoting of attribute values in HTML tags.  Using single quotes to
enclose values in PHP has a marginal performance benefit over using double
quotes since single quotes don't have to be interpolated (parsed) by PHP.
When I'm dealing with HTML tags with attribute values, I tend to use the
following syntax:

echo 'My name is <a href="' . $url . '">' . $name . '</a>';

Otherwise, I tend to place everything within double quotes.

echo "My name is $name.";

YMMV.  FYI, a technique that is sometimes useful is to enclose variables
within single quotes and then interpolate them later using the eval()
function.  I sometimes do this within applications where I have dozens of
dynamic queries whose SQL statements change depending on user action (like
clicking a field heading to sort on).  I will store the SQL statements in a
separate file which in include()ed within my app, then use eval() to
interpolate them *after* the needed variables are set within the webpage.
For example, my include file will have code like:

$sql_103  = 'SELECT quantity, price';
$sql_103 .= 'FROM orders ';
$sql_103 .= 'WHERE user = "$user"';

And my main script will include the queries file and have code like:

// user variable comes from user input via form post.
// assume it was "Steve".
$user = $HTTP_POST_VARS['user'];

eval("\$sql_103 = \"$sql_103\";");

Then I can go about executing the query b/c $sql_103 now has a value of:

SELECT quantity, price FROM orders WHERE user = "Steve"

And the reason I store the SQL statements in a single file is b/c they're
easier to find, easier to change since many times the same SQL statements
are used in several scripts and I can avoid changing in multiple places,
with multiple users working on a project everyone knows where to find all
queries and whether one has already been created that they can use, it makes
documentation of the code and debugging a lot easier.

Hope this helps someone.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: PHP calling PHP?
@ 2001-05-11 14:52  Roberto Mello <rmello@cc.usu.edu>
  parent: Chris Smith <csmith@squiz.net>
  2 siblings, 0 replies; 17+ messages in thread

From: Roberto Mello @ 2001-05-11 14:52 UTC (permalink / raw)
  To: Chris Smith <csmith@squiz.net>; +Cc: pgsql-php

On Thu, May 10, 2001 at 03:23:31PM +1000, Chris Smith wrote:
> 
> > > > echo "<FORM ACTION=\"$PHP_SELF\" METHOD=\"POST\">\n";
> > >
> > > 	Ack! You could do this for much better readability instead:
> > > echo "<FORM ACTION='$PHP_SELF' METHOD='POST'>\n";
           ^^^^^^^^^^^^^^^^
> Different quotes do different things in PHP, just something to remember...

	True, but that's not what I did. My line of code is correct. The
single quotes are within the double quotes, and hence are treated as
literals and the variable is evaluated.

	-Roberto

-- 
+----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+
  Roberto Mello - Computer Science, USU - http://www.brasileiro.net 
       http://www.sdl.usu.edu - Space Dynamics Lab, Developer    
* * * <- Tribbles  § § § <- teenage mutant ninja tribbles



^ permalink  raw  reply  [nested|flat] 17+ messages in thread


end of thread, other threads:[~2001-05-11 14:52 UTC | newest]

Thread overview: 17+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-05-05 12:51 PHP calling PHP? Christian Marschalek <cm@chello.at>
2001-05-05 13:32 ` Gyozo Papp <pgerzson@freestart.hu>
2001-05-05 15:40   ` Christian Marschalek <cm@chello.at>
2001-05-05 16:09     ` Gyozo Papp <pgerzson@freestart.hu>
2001-05-08 04:04       ` Steve Werby <steve-lists@befriend.com>
2001-05-08 04:19         ` Grant <grant@conprojan.com.au>
2001-05-08 04:34           ` Chris Smith <csmith@squiz.net>
2001-05-08 04:42             ` Grant <grant@conprojan.com.au>
2001-05-08 05:16             ` Mitch Vincent <mitch@venux.net>
2001-05-10 04:36           ` Steve Werby <steve-lists@befriend.com>
2001-05-10 04:54             ` Grant <grant@conprojan.com.au>
2001-05-10 05:03               ` Roberto Mello <rmello@cc.usu.edu>
2001-05-10 05:10                 ` Grant <grant@conprojan.com.au>
2001-05-10 05:23                   ` Chris Smith <csmith@squiz.net>
2001-05-10 05:32                     ` Christian Marschalek <cm@chello.at>
2001-05-10 15:54                     ` Steve Werby <steve-lists@befriend.com>
2001-05-11 14:52                     ` Roberto Mello <rmello@cc.usu.edu>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox