Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18041 > unrolled thread
| Started by | Dan Wissme <wissme@free.fr> |
|---|---|
| First post | 2019-08-24 18:14 +0200 |
| Last post | 2019-08-26 09:27 +0200 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.lang.php
Beginner question on using PHP and POST Dan Wissme <wissme@free.fr> - 2019-08-24 18:14 +0200
Re: Beginner question on using PHP and POST "R.Wieser" <address@not.available> - 2019-08-24 18:47 +0200
Re: Beginner question on using PHP and POST "R.Wieser" <address@not.available> - 2019-08-24 18:53 +0200
Re: Beginner question on using PHP and POST Martin Leese <please@see.Web.for.e-mail.INVALID> - 2019-08-24 12:35 -0600
Re: Beginner question on using PHP and POST Martin Leese <please@see.Web.for.e-mail.INVALID> - 2019-08-24 13:04 -0600
Re: Beginner question on using PHP and POST Jeroen Belleman <jeroen@nospam.please> - 2019-08-24 23:59 +0200
Re: Beginner question on using PHP and POST Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-08-25 01:31 +0100
Re: Beginner question on using PHP and POST Arno Welzel <usenet@arnowelzel.de> - 2019-08-26 09:27 +0200
| From | Dan Wissme <wissme@free.fr> |
|---|---|
| Date | 2019-08-24 18:14 +0200 |
| Subject | Beginner question on using PHP and POST |
| Message-ID | <5d616255$0$31423$426a74cc@news.free.fr> |
I write an HTML page foods.html containing a form like :
<form method="post" action="process.php">
<p><input type="text" name="food" id="food"></p>
<input type="submit" value="OK">
</form>
The purpose is to get from user the name of the food and open a web page
already existing about that food. The user may ask for 'meat' for
example. I will then open the web page meat.html
So I wrote a file "process.php" like that one :
<?php
$food=htmlspecialchars($_GET["food"]);
<--------- what then ?
?>
I tried echo, readfile, etc but got nothing...
Thanks,
-dan
[toc] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-08-24 18:47 +0200 |
| Message-ID | <qjrpnf$52c$1@gioia.aioe.org> |
| In reply to | #18041 |
Dan, Two things: > $food=htmlspecialchars($_GET["food"]); You are POSTing, but are inspecting the $_GET array ? No wonder you do not get anything (see what I did there ? :-) ) Suggestion: Try to inspect the $_POST array instead. Some info: https://www.php.net/manual/en/reserved.variables.post.php > I tried echo, readfile, etc but got nothing... Correction, you did not /see/ anything. Next time when you are not sure what, or even if you should see anything delimit the output with a few know characters. My favorites are the square brackets: echo "[". $food ."]" Maybe throw in a carriage-return and linefeed for good measure too: echo "[". $food ."]\r\n" remark: Apologize for any errors or glaring omissions - I'm a PHP novice myself too. :-) Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-08-24 18:53 +0200 |
| Message-ID | <qjrq3f$6ol$1@gioia.aioe.org> |
| In reply to | #18042 |
Dan, Also take a look at the $_REQUEST array (combination of GET, POST and COOKIE arrays): http://www.shodor.org/~kevink/phpTutorial/nileshc_getreqpost.php Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | Martin Leese <please@see.Web.for.e-mail.INVALID> |
|---|---|
| Date | 2019-08-24 12:35 -0600 |
| Message-ID | <qjs00u$s7e$1@dont-email.me> |
| In reply to | #18041 |
Dan Wissme wrote: ... > The purpose is to get from user the name of the food and open a web page > already existing about that food. The user may ask for 'meat' for > example. I will then open the web page meat.html Perhaps I have misunderstood what it is you are trying to do, but what is wrong with a list of links? The pages such as meat.html already exist, so you know the list of links to offer. Something like: <ul> <li><a href="meat.html">Meat</a></li> <li><a href="vegies.html">Vegies</a></li> ... </ul> Alternatively, put them in a <select> list. Something like: <form method="POST" action="..."> <p> <select id="food"> <option value="meat.html">Meat</option> <option value="vegies.html">Vegies</option> ... </select> <button type="button" onclick="displayPage();">Display page</button> </p> <form> Writing the JavaScript function displayPage() has been left as an exercise for Dan :-) Neither approach comes anywhere near PHP; I see no need for PHP. -- Regards, Martin Leese E-mail: please@see.Web.for.e-mail.INVALID Web: http://members.tripod.com/martin_leese/
[toc] | [prev] | [next] | [standalone]
| From | Martin Leese <please@see.Web.for.e-mail.INVALID> |
|---|---|
| Date | 2019-08-24 13:04 -0600 |
| Message-ID | <qjs1os$66a$1@dont-email.me> |
| In reply to | #18044 |
Martin Leese wrote: ... > Writing the JavaScript function displayPage() > has been left as an exercise for Dan :-) Hi Dan, I tried to e-mail you some (untested) JavaScript to get you going, but the e-mail bounced with the message: 550 5.2.1 This mailbox has been blocked due to inactivity (UserSearch) If you would like the JavaScript code then please e-mail me. -- Regards, Martin Leese E-mail: please@see.Web.for.e-mail.INVALID Web: http://members.tripod.com/martin_leese/
[toc] | [prev] | [next] | [standalone]
| From | Jeroen Belleman <jeroen@nospam.please> |
|---|---|
| Date | 2019-08-24 23:59 +0200 |
| Message-ID | <qjsc0s$l9h$1@gioia.aioe.org> |
| In reply to | #18041 |
On 2019-08-24 18:14, Dan Wissme wrote: > I write an HTML page foods.html containing a form like : > > <form method="post" action="process.php"> > <p><input type="text" name="food" id="food"></p> > <input type="submit" value="OK"> > </form> > > > The purpose is to get from user the name of the food and open a web page > already existing about that food. The user may ask for 'meat' for > example. I will then open the web page meat.html > > So I wrote a file "process.php" like that one : > > <?php > $food=htmlspecialchars($_GET["food"]); > <--------- what then ? > ?> > > I tried echo, readfile, etc but got nothing... > Thanks, > > -dan > If the form's method is 'POST' the variables are accessed in PHP as $_POST["food"]. $_GET is used only when the method is "get". Jeroen Belleman
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2019-08-25 01:31 +0100 |
| Message-ID | <87imqmccg8.fsf@bsb.me.uk> |
| In reply to | #18041 |
Dan Wissme <wissme@free.fr> writes:
> I write an HTML page foods.html containing a form like :
>
> <form method="post" action="process.php">
> <p><input type="text" name="food" id="food"></p>
> <input type="submit" value="OK">
> </form>
>
>
> The purpose is to get from user the name of the food and open a web
> page already existing about that food. The user may ask for 'meat' for
> example. I will then open the web page meat.html
>
> So I wrote a file "process.php" like that one :
>
> <?php
> $food=htmlspecialchars($_GET["food"]);
> <--------- what then ?
> ?>
You don't need htmlspecialchars, but you should sanitise the input. For
example, you could check that $_POST['food'] (or $_REQUEST['food'])
contains nothing but lowercase letters.
> I tried echo, readfile, etc but got nothing...
You could use PHP's header function like this:
header("Location: $food.html");
exit();
This cases the HTTP response to include a redirection header. A
confirming browser will then request the HTML document in question.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-08-26 09:27 +0200 |
| Message-ID | <gshfvaFl3tnU5@mid.individual.net> |
| In reply to | #18041 |
Dan Wissme: > I write an HTML page foods.html containing a form like : > > <form method="post" action="process.php"> > <p><input type="text" name="food" id="food"></p> > <input type="submit" value="OK"> > </form> > > > The purpose is to get from user the name of the food and open a web page > already existing about that food. The user may ask for 'meat' for > example. I will then open the web page meat.html > > So I wrote a file "process.php" like that one : > > <?php > $food=htmlspecialchars($_GET["food"]); > <--------- what then ? > ?> > > I tried echo, readfile, etc but got nothing... Because you POST things you need $_POST[]. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web