/    Sign up×
Community /Pin to ProfileBookmark

Can’t get the most simple PHP example to work…

I am new to PHP and learning it using examples and online tutorials.
My goal is to use an HTML form (with a ‘Submit’ button) for collecting inputs from the user and then using PHP to collect the inputs and process them on the server.
I have tried several examples that were available online, but couldn’t get any of them to work on my computer.
This example is supposed to collect an input and simply echo it back.

[B][I][U]The HTML code:[/U][/I][/B]
[I][COLOR=”DarkOrange”]<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form action=”process.php” method=”post”>
<select name=”item”>
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
Quantity: <input name=”quantity” type=”text” />
<input type=”submit” />
</form>
</body></html>[/COLOR]
[/I]

[B][U]The PHP code (file saved as “process.php”):[/U][/B]
[I][COLOR=”DarkOrange”]<html><body>
<?php
$quantity = $_POST[‘quantity’];
$item = $_
POST[‘item’];
echo “You ordered “. $quantity . ” ” . $item . “.<br />”;
echo “Thank you for ordering from Tizag Art Supplies!”;
?>
</body></html>[/COLOR]
[/I]

[B][U]The output (in Chrome):[/U][/B]
[COLOR=”DarkOrange”]“; echo “Thank you for ordering from Tizag Art Supplies!”; ?>[/COLOR]

Thanks in advance for your support! ?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@evenstar7139Aug 20.2012 — Hi, and welcome to the forum.

Did you install PHP on your computer?

If so, maybe you're saving your files in the wrong folder? I seem to remember, back when I was running PHP on my computer, that my files would only run if I saved them in the right directory. I was using Xampp (some thingy that comes with PHP, a web server, and other stuff) so it was c:xampphtdocsxampp

I try to help people here but I'm not that good at it yet. If I have failed to be of any assistance, fear not, somebody much more experienced than me will reply ?
Copy linkTweet thisAlerts:
@simtomauthorAug 20.2012 — Thanks Evenstar for your reply.

I have Microsoft Expression Web recent version installed, although those program files were not created using it.

Do i still need to install PHP?

By the way, the two program files are located at the same folder.

Thanks for your help.
Copy linkTweet thisAlerts:
@donatelloAug 20.2012 — I just answered this for someone on the previous thread...

http://www.webdeveloper.com/forum/showthread.php?t=263708


There are 4 examples laid out for you to demonstrate it in PHP and Javascript. All are working.
Copy linkTweet thisAlerts:
@donatelloAug 20.2012 — [code=php]
<h2>Enter your text in the form</h2>
<form name="form1" method="post" action="">
<input type="text" name="something" size="36" /> &nbsp;&larr; Enter some short text here.<br />
<textarea rows="3" cols="55" name="text"></textarea> &nbsp;&larr; Enter long text here.<br />
<input type="submit" value="Go" />
</form>
<div id="mydiv" name="mydiv">
<?php

// The lines below capture the data sent from the form
$something = $_POST['something'];
$text = $_POST['text'];

// The next lines (below) return some text if the forms are both empty
if(empty($something) && empty($text)) {
echo 'XXXXXXXXX - This is some text - XXXXXXXXXXXXX';
} else {

// The lines below use "HEREDOC" to simply output whatever was typed into the forms
echo <<<EOD
<b>$something</b><br /> $text
EOD;
}

?>
</div>
[/code]
Copy linkTweet thisAlerts:
@donatelloAug 20.2012 — form.html
[code=html]
<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form action="process.php" method="post">
<select name="item">
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
Quantity: <input name="quantity" type="text" />
<input type="submit" />
</form>
</body>
</html>
[/code]


File: process.php
[code=php]

<html>
<body>
<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];
echo "You ordered $quantity $item <br />";
echo 'Thank you for ordering from Tizag Art Supplies!';
?>
</body>
</html>

[/code]
Copy linkTweet thisAlerts:
@tracknutAug 20.2012 — Thanks Evenstar for your reply.

I have Microsoft Expression Web recent version installed, although those program files were not created using it.
[/QUOTE]


Expression Web does not come with PHP, so if you're trying to run these on your local computer, you do need PHP installed.

Dave
Copy linkTweet thisAlerts:
@DasherAug 20.2012 — You might consider installing XAMPP or WAMP on your system. They provide support for apache web server, mysql, and php. Both are free. You can still use your MS program to make pages with.

Also local web pages must be opened as a url such as //localhost/index.php and [B]not[/B] as a file i.e. file://c:/somepath/index.php.
Copy linkTweet thisAlerts:
@evenstar7139Aug 20.2012 — Wow so I was right about the possibility of simtom not having PHP installed? Yay! I feel useful now.
×

Success!

Help @simtom spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...