Thread: 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
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
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 >
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 > ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
"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/ ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster
> Also, variables cannot have numbers in their name, but a variable variables > workaround allows them to be used. For example: Wrong.
> > 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?
> > 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 ~#
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 >
"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/
> 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> ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
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. ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> > 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.
> > > 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
> 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;) ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html
"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/
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 ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://www.postgresql.org/search.mpl
> 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;) ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html
> 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> ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
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 > ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
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 ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://www.postgresql.org/search.mpl
"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/ ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster
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. ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org