PHP help!
ok I'm really new to PHP, I like just started learning it about a week ago, anyway heres my problem:
I started working on the basic form with HTML you know the <form> tag. I wanted to make a form with HTML that you enter information and the information which is entered is processed to a PHP script, I used the POST method I'm sure all you know and used the $_POST array to get the names of the forms data. I enter the right names in the HTML form and the PHP $_POST array, this is what the HTML script looks like:
<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>
and this is the PHP script
$quantity = $_POST['quantity'];
$item = $_POST['item'];
echo $quantity . '<br>' . $item ;
?>
but when I run the PHP on Apache server it comes up with this error:
**Notice:**Undefined index: on line 3
Now I don't know what's wrong but it might be the array, but of course please correct me if I'm wrong
one more thing when I'm testing out the HTML form and submit, it downloads the PHP file into notepad and opens it, not running the PHP script…
like I said I'm very new with PHP and this is just for testing. I have watch alot of tutorials on this subject but can't seem to get it to work.
thanks for your help!
when you run php on apache, does that mean when you run a php script or when trying to start apache???
cause from your problem it sems that php is not running on your computer, if it did the php file eill not download.
just to make life easier with those things … uninstall apache, php, mysql . then download xampp.
would work great for testing. almost no config is needed
stealth- wrote: You must have misconfigured apache/PHP somewhere along the lines, or don't have PHP installed correctly. Or he's just running the PHP script without submitting through the form he created, meaning he's sending no values to it to be found… Maybe he thinks that what he's written is a program that needs to be running and listening for the information to handle it, fuck knows.
COM- wrote: Or he's just running the PHP script without submitting through the form he created, meaning he's sending no values to it to be found…
I guess that was the first problem, thats why it was undefined becuase I went right the PHP server and tested it and didn’t submit the array data. thanks! :D
but I still don't know why it's downloading the source of the PHP script onto notepad and not running the script into the browser 0.o
FACEPALM "… running the script into the browser"
PHP - Pre-Hypertext Processor - just by breaking down the name, "pre-hypertext" IE server side, before HTML output, some form of processing is/maybe performed.
Other languages such as: JSP (Java Server Page), ASP[X] (Active Server Page) and CFM (ColdFusion Markup Language) CGI extensions for Perl/Ruby and Python also work in the same vein.
Unless you are running this on some hosting which is unsuitable for PHP - in which case go and register at one of the many free PHP hosting sites.
As already stated by stealth- & ADIGA if you are developing from your PC with a local server, you need to have installed on your local machine/local server:
i)Apache ii)PHP (Maybe an SQL server if you are thinking of going on to doing some Database driven scripts)
More importantly, you need to configure Apache to handle PHP if you have not installed it or the installer could not automatically configure Apache to handle PHP scripts.
Since I don't know what OS you're running I've kept this guidance general.
Apache
If you installed PHP after apache, you need to make sure that it correctly automatically configured apache, go to your apache folder and look at:
conf/httpd.conf
...
LoadModule phpN_module "[drive:]/path/to/php/phpNapache2[_2].[dll/so]"
AddType application/x-httpd-php .php
...
PHP
PHP may need some configuration to run certain libraries you intend to use such as: database/graphics manipulation/encryption/encoding librarires.
This can all be found in the php.ini however be sure to check from PHPInfo for the path to your php.ini, usually in the same directory as your installation of PHP.
Jim
so that's it! I had XAMPP installed and running but I wasn't running the HTML page into the server and therefore not running the PHP script into the server. HTML of course doesn't need a server but PHP does, so thats why HTML was working and PHP was not.
thank you all for replying and helping me.
Thanks a ton!;)