Welcome! Log In Create A New Profile

Advanced

PHP Four - Working with HTML Forms

Posted by 70859159 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
PHP Four - Working with HTML Forms
July 08, 2012 07:53PM
I found an error in php4p7.html - 7. Checking if the Submit button was clicked.

The name of the submit button is wrong.

The line in red: if (isset($_POST['Submit'])) {
should be: if (isset($_POST['Submit1'])) {
Re: PHP Four - Working with HTML Forms
July 08, 2012 08:00PM
Completed PHP Four.
avatar Re: PHP Four - Working with HTML Forms
July 17, 2012 07:41PM
Using Dreamweaver to code, because i didnt understand PHPedit, anyhoo, My code didnt run because i made a Mistake in the exercise with a Variable name, nasty if you cant spot the difference between a "n" and a "N" spinning smiley sticking its tongue out. Completed PHP four.

@70859159 there are a few typo's I Picked up, didnt take them down tho, even in the tut_101 - "4.2 Cpourse" made me giggle smiling bouncing smiley Sorry Mac

Lance Malgas
Re: PHP Four - Working with HTML Forms
July 27, 2012 09:58AM
Hi guys,

can somebody please tell wat im doing wrong...please have a look at my code below.

order.html
Language: PHP
<html> <head> <title></title> </head> <body> <h4>Art supply order form</h4> <form action = "process.php" method ="Action"> Item : <select name = "item"> <option>Brushes</option> <option>Paint</option> <option>Erasers</option> </select> Quantity: <input name ="quantity" type ="text" /> <input type="submit"/> </form> </body> </html>


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


i get an error that says 'quantity' and 'item' aren't defined...i dnt really know what could be the problem... please help!!
Anonymous User
Re: PHP Four - Working with HTML Forms
July 27, 2012 04:43PM
Hi Sandra, is your browser reading the script and not your server?, if so, don't click on the file to open it, launch your server firstly, then call
the html file eg. localhost/order.html (wherever the html doc is located) or click here to your launch your server>> http://localhost/order.html,
fill in your order form then try it
avatar Re: PHP Four - Working with HTML Forms
July 27, 2012 06:11PM
Hi Sandra

I tried your script and it gave me the same error, I changed the method to "post" and it worked fine. In the process script you're telling php your Variable is $_POST['quantity'] and $_POST['item'], but you haven't told your form to Post the info. See below. Hope this helps.

Language: PHP
<html> <head> <title></title> </head> <body> <h4>Art supply order form</h4> <form action = "process.php" method ="post"> Item : <select name = "item"> <option>Brushes</option> <option>Paint</option> <option>Erasers</option> </select> Quantity: <input name ="quantity" type ="text" /> <input type="submit"/> </form> </body> </html>
Re: PHP Four - Working with HTML Forms
July 30, 2012 10:03AM
Thanks for ur help Guys...much appreciatedsmile
Re: PHP Four - Working with HTML Forms
July 30, 2012 06:14PM
I would like to know if the following:

VALUE="<?PHP print $username; ?>"

shouldn't have been written like this?

VALUE="<?php print ($username); ?>"

I couldn't really see what it does. Nothing is returned when you click the button.
Re: PHP Four - Working with HTML Forms
July 30, 2012 07:04PM
Is there an easier way to check the 5 usernames?

Language: PHP
<html> <head> <title>A BASIC HTML FORM</title>   <?php if (isset($_POST[';Submit1';])) { $username=$_POST[';username';];   if ($username=="fox") { print ("Welcome back, friend!"); } else if($username=="wolf") { print ("Welcome back, friend!"); } else if($username=="jackal") { print ("Welcome back, friend!"); } else if($username=="hound") { print ("Welcome back, friend!"); } else if($username=="dog") { print ("Welcome back, friend!"); } else { print ("You';re not a member of this site"); } } ?>   </head> <body>   <FORM NAME="form1" METHOD="POST" ACTION="formexercise2.php">   <INPUT TYPE="TEXT" Name="username" VALUE="username">   <INPUT TYPE="Submit" Name="Submit1" VALUE="Login">   </FORM>       </body> </html>
Re: PHP Four - Working with HTML Forms
July 30, 2012 09:56PM
Have reworked this section, it is quite cool what can be achieved. Now just to fugure out how to create a function that will check if data entered is secure
Re: PHP Four - Working with HTML Forms
July 31, 2012 05:22AM
Have completed this section too, was having problems with getting the isset function right for a GET method, but after checking the syntax correctly, I now fully comprehend it. I think the POST method despite being secure is the best to use for submitting data.
avatar
Mac
Re: PHP Four - Working with HTML Forms
July 31, 2012 07:56AM
To help with error checking it is sometimes a good idea to use $_GET until you find the error, because then you can see if the variables collected by a form, for example, is being passed correctly, and what it is passed as

Language: PHP
//URL looks like this on receiving page file.php?init=TM&sname=vdMerwe &email=here@there.com&hits=95

It is easy to see the values are being correctly captured in the form and passed, and also how you need to capture it.

Language: PHP
$initials=$_GET[';init';]; //After error checking, change the form to post and this to $initials=$_POST[';init';]; $surname=$_GET[';sname';]'; //After error checking, change the form to post and this to $surname=$_POST[';sname';] //etc.
Re: PHP Four - Working with HTML Forms
July 31, 2012 05:16PM
Done with Section 4 and 5..starting 6 tonight after work.Eish! sad smiley i am so behind but hope to catch up soon
avatar
Mac
Re: PHP Four - Working with HTML Forms
August 01, 2012 07:19AM
77686160 Wrote:
-------------------------------------------------------
> Is there an easier way to check the 5 usernames?

Language: PHP
... if ($username=="fox" || $username=="wolf" || $username=="jackal") { //etc. print ("Welcome back, friend!"); } else { print ("You';re not a member of this site"); }
avatar
Mac
Re: PHP Four - Working with HTML Forms
August 01, 2012 07:20AM
77686160 Wrote:
-------------------------------------------------------
> I would like to know if the following:
>
> VALUE="<?PHP print $username; ?>"
>
> shouldn't have been written like this?
>
> VALUE="<?php print ($username); ?>"
>
> I couldn't really see what it does. Nothing is
> returned when you click the button.

print can use brackets, your choice. IF nothing is returned it is not because of this.
Re: PHP Four - Working with HTML Forms - Done
August 01, 2012 08:42PM
Done with this section and going forward, there was an error on the supplied code the comparison operator had a space between it "= =" when it is suppose to be "=="
Re: PHP Four - Working with HTML Forms
August 16, 2012 05:57PM
Complete!
avatar Re: PHP Four - Working with HTML Forms
August 21, 2012 10:45PM
Just finished Section 4 ..
Took a bit longer than expected due to some spelling errors

@70859159 - Thanks for pointing out and making me aware of said errors

@77686160 and Mac - Thanks for having and solving the same problem i was working on smiling smiley
Re: PHP Four - Working with HTML Forms
September 03, 2012 09:14PM
@70859159 - Thanks for pointing out the error.

I am having trouble with getting the surname to print in the first exercise php4p9 - can someone please assist?

Language: PHP
<html> <head> <title>A BASIC HTML FORM</title>   <?php   if(isset($_POST[';Submit1';])) {   $name=$_POST[';name';]; $surname=$_POST[';surname';];   if($name==';John';) { print(';John';); }   } else { $name=""; }   if($surname==';Doe';) { print(';Doe';); }     else { $surname=""; }     ?> </head> <body>       <FORM NAME="form1" METHOD="POST" ACTION="basicForm_namesurname.php">   <INPUT TYPE="TEXT" VALUE="<?PHP print$name;?>" NAME="name"> <INPUT TYPE="TEXT" VALUE="<?PHP print$surname;?>" NAME="surname"> <INPUT TYPE="Submit" Name="Submit1"VALUE="Login">         </FORM>     </body>             </html>
Re: PHP Four - Working with HTML Forms
September 03, 2012 09:26PM
I realise now that what I was trying to do in the above text is actually the second exercise. I am stuck with both first and second exercise. Will try tackle the third...
Re: PHP Four - Working with HTML Forms
September 05, 2012 10:21PM
Still struggling with chapter four, starting over to see where I am going wrong.
Re: PHP Four - Working with HTML Forms
September 06, 2012 10:01PM
In my quest to get through Chapter Four - I found this page, I find it quite useful:
http://www.w3.org/TR/html401/interact/forms.html
Re: PHP Four - Working with HTML Forms
September 09, 2012 05:57PM
PHP Four completed finally, really struggled here - I tried different ways of setting up a form for the 5 usernames, including conditional logic and switch statements. On to chapter 5.
Sorry, only registered users may post in this forum.

Click here to login