Welcome! Log In Create A New Profile

Advanced

Text book Chapter 5

Posted by 78044545CharlesU 
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
Text book Chapter 5
September 05, 2013 10:34AM
Hi there,

The variable $foo appears so often in opensource applications. Does it have a special
significance? It is used on page 148. Then on page 149 it is used in the sentence and not as
a variable " This code will fail.The echo function will send the headers with the text " foobar"."

Curious
avatar Re: Text book Chapter 5
September 05, 2013 12:39PM
I think it is a sort of a theme that they use. It's like almost all programming languages starting off with a Hello World example.


78044545CharlesU Wrote:
-------------------------------------------------------
> Hi there,
>
> The variable $foo appears so often in
> opensource applications. Does it have a special
> significance? It is used on page 148. Then on page
> 149 it is used in the sentence and not as
> a variable " This code will fail.The echo function
> will send the headers with the text "
> foobar"
."
>
> Curious
avatar Re: Text book Chapter 5
September 05, 2013 01:11PM
Its just a nonsense word that has no special meaning, it could be anything. Much like using "Joe Soap" or "Joe Bloggs" for anybody / nobody in particular.

Look here for a full discussion of the word -

Language: HTML
http://en.wikipedia.org/wiki/Foobar
Re: Text book Chapter 5
September 05, 2013 02:53PM
Hi,

Read it up, thanks! This chapter also states that Multiple Submit Buttons on the same page share the same name. I've given
them different names with good results. Should I be expecting a meltdown later on? Or if ti works leave it alone!

Charles
avatar Re: Text book Chapter 5
September 05, 2013 03:17PM
If it's not broken don't fix it...spinning smiley sticking its tongue out

Although it does look neater coding wise if you make use of a switch statement to handle all the buttons on your page. Like this:

Language: PHP
if(isset($_POST[';submit';])){ $btnClick = ($_POST[';submit';]); switch($btnClick){ case "Logout": << Logout is the name of the value button   break;   case "Check Form": <<Check Form is the name of the value button   break;     case "Register": <<Register is the value of the submit button   break;

The HTML will then look like this:

Language: HTML
<input type="submit" name="submit" value="Register" tabindex="21" > <input type="submit" name="submit" value="Check Form" tabindex="20"> <input type="submit" name="submit" value="Clear" tabindex="19">




78044545CharlesU Wrote:
-------------------------------------------------------
> Hi,
>
> Read it up, thanks! This chapter also states that
> Multiple Submit Buttons on the same page
> share the same name. I've given
> them different names with good results. Should I
> be expecting a meltdown later on? Or if
> ti works leave it alone!
>
> Charles
avatar Re: Text book Chapter 5
September 05, 2013 03:22PM
If the Buttons have the same name there is no way to distinguish between them in the script that processes the form.
They basically have to have different names if they do different things.

Look here for an example -

http://www.techrepublic.com/article/handling-multiple-submits-in-a-single-form-with-php/


Ooops - should have read the link to the end -

You can use either the name or the value of the buttons.
avatar Re: Text book Chapter 5
September 05, 2013 03:26PM
Check my example above.


bigron11 Wrote:
-------------------------------------------------------
> If the Buttons have the same name there is no way
> to distinguish between them in the script that
> processes the form.
> They basically have to have different names if
> they do different things.
>
> Look here for an example -
>
> http://www.techrepublic.com/article/handling-multi
> ple-submits-in-a-single-form-with-php/
Re: Text book Chapter 5
September 06, 2013 07:12PM
Hi bigron11 and AlexB,

I've finally worked it out and got it working!!! It does seem to make for neater coding and I think it will
also save save on using the if(isset) function all over the place. by the way an interesting site, will go there again.

Thanks,

CharlesU
Re: Text book Chapter 5
September 07, 2013 09:39AM
Hi All,

Took some time, but finally realized what Prof mac means by we can all contribute! Instead of thanking each other,
pass the knowledge on! Learning to use submit buttons of the same name resulted in this crude but simple coding
which can be used for adding and deleting of courses.

<?php

//The connection to the database is in the config.php page

require('config.php'winking smiley;

if(isset($_POST['Submit'])){

$newcourse=$_POST['newcourse'];
$oldcourse=$_POST['oldcourse'];
$switch_it =$_POST['Submit'];

//Add: The new course name
//Delete: The old course number

switch($switch_it){
case 'Add':

$sql="INSERT INTO course
(cname)
VALUES('$newcourse'winking smiley";

$result=mysql_query($sql);

break;
case 'Delete':

$sql = "DELETE FROM course
WHERE cid = '$oldcourse'";

$result=mysql_query($sql);
break;
}
}
?>
Re: Text book Chapter 5
September 09, 2013 01:35PM
Hi Guys,

Can anyone tell me what am I doing wrong? I get an error message: Notice: Undefined index: Name in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\formprocess1.php on line 7 when doing the exercise on page 137 in the Text book. I have copied the code exactly as in the textbook, as follows:

Language: PHP
<html> <head> <title>Say my Name</title> </head> <body> <?php echo "Hello " .$_POST[';Name';]; ?> <pre> DEBUG: <?PHP print_r ($_POST); ?> </PRE> </BODY> </HTML>   it says the error is in line 7, which is "echo "Hello" .$_POST[';Name';];" I am not sure what I am doing wrong, I am so frustrated, as this is the start of the chapter and already I am having problems to let this work.   Any help will be much appreciated.   Thanks   Zelda
Re: Text book Chapter 5
September 09, 2013 04:09PM
Hi Zelda,

I copied and pasted you code into my text editor and worked perfectly!
It may be your php installation issues, sorry that I can not help
avatar Re: Text book Chapter 5
September 09, 2013 04:23PM
Is "Name" used exactly the same in both scripts ?

eg "Name" vs "name"
avatar Re: Text book Chapter 5
September 09, 2013 04:50PM
You may want to have a look at installing EasyPHP in another directory rather than C:\Program Files for instance rather C:\EasyPHP. Some permissions on the Program Files folder cause weird problems.

I used XAMPP because of some weird things happening in EasyPHP.



Zelda-78024447 Wrote:
-------------------------------------------------------
> Hi Guys,
>
> Can anyone tell me what am I doing wrong? I get
> an error message: Notice: Undefined index: Name in
> C:\Program Files
> (x86)\EasyPHP-5.3.5.0\www\formprocess1.php on line
> 7 when doing the exercise on page 137 in the Text
> book. I have copied the code exactly as in the
> textbook, as follows:
>
>
Language: PHP
> <html> > <head> > <title>Say my Name</title> > </head> > <body> > <?php > echo "Hello " .$_POST[';Name';]; > ?> > <pre> > DEBUG: > <?PHP > print_r ($_POST); > ?> > </PRE> > </BODY> > </HTML> > > it says the error is in line 7, which is "echo > "Hello" .$_POST[';Name';];" > I am not sure what I am doing wrong, I am so > frustrated, as this is the start of the chapter > and already I am having problems to let this > work. > > Any help will be much appreciated. > > Thanks > > Zelda > > >

___________________________________________________________________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning...
Re: Text book Chapter 5
September 10, 2013 01:58AM
Hi,

Another tip. All the code for the text book is available for download at www.wrox.com. If their code runs, and mine doesn't. I know I've made a mistake and start looking!
However, in this case it's their mistake. Name the first form, form1.php and not form1.html as stated.

CharlesU
avatar
Mac
Re: Text book Chapter 5
September 10, 2013 07:24AM
Re: Text book Chapter 5
September 10, 2013 10:49AM
Thanks for your responses. Will definitely have a look at the suggestions given. Your time is much appreciated.
Re: Text book Chapter 5
September 10, 2013 08:36PM
Hi there,
Me again. I am still having the same problem. I have tested it on xampp, and I get the same notice error message. I did what the website [siliconstation.com] said, and still the same error message.

I will load both code pages if anyone can please tell me what am I missing.

form1.php

Language: PHP
<html> <head> <title>Say my Name</title> Style type="text/css"> TD{COLOR:#353535;FONT-FAMILY:VERDANA} TD{COLOR:#FFFFFF;FONT-FAMILY:VERDANA;BACKGROUND-COLOR:#336699} </style> </head> <body> <form action="formprocess1.php" method="POST"> <table border="0" cellspacing="1" cellpadding="3" bgcolor="#353535" align="center"> <tr> <td bgcolor = "#FFFFFF" width = "50%"> Name</td> <td bgcolor="#FFFFFF" width= "50%"> <input type="text" name="Name"><br> </td> </tr> <tr> <td bgcolor ="#FFFFFF" colspan ="2" align="center"> <input type="submit" name="SUBMIT" VALUE="Submit"> </td> </tr> </table> </form> </body> </html>





and formprocess1.php



Language: PHP
<html> <head> <title>Say my Name</title> </head> <body> <?php if(isset($_POST[';Name';])){ $notify = $_POST[';Name';]; } echo "Hello " . $_POST[';Name';]; ?> <pre> DEBUG : <?PHP print_r ($_POST); ?> </PRE> </BODY> </HTML>





I have added the "if-isset" as per the website, but don't know what to do.

Thanks again for everyone's input, I am learning although I am stuck.
avatar
Mac
Re: Text book Chapter 5
September 10, 2013 09:16PM
using isset you have set $notify... but then do not use it in your echo statement.

Language: PHP
<?php if(isset($_POST[';Name';])){ $notify = $_POST[';Name';]; } echo "Hello " . $_POST[';Name';]; // this is not set! echo "Hello " . $notify; //$notify is set ?>!

Do not get frustrated. 99% of the time is because we think way ahead. I have spend a whole day... and missed a typo which my or your grandmother would have picked up. Get used to it. You will also find yourself thinking about it the whole day. And that is cool, because the PHP bug has bitten you smiling smiley

And just to prove it - I looked at your code. Could not pick any "error" up initially. I cnduo't bvleiee taht I culod aulaclty mesisd it! Tihs is bucseae the huamn mnid deos not raed ervey ltteer by istlef, but the stametnet as a wlohe. Aaznmig, huh?
Re: Text book Chapter 5
September 11, 2013 09:13AM
Thanks Prof Mac for the laugh, It cheered me upsmile.

I did exactly as you said, and now its giving me this error.

Notice: Undefined index: Name in C:\xampp\htdocs\portfolio\formprocess1.php on line 8
Hello
Notice: Undefined variable: notify in C:\xampp\htdocs\portfolio\formprocess1.php on line 9
Hello ! DEBUG :
Array
(
[SUBMIT] => Submit
)

What I also notice is that it does not say "Hello Test" or whatever I fill in the textbox.
I'm not sure what it is, could it be the program, or meconfused smiley
avatar Re: Text book Chapter 5
September 11, 2013 09:19AM
Language: PHP
<?php if(isset($_POST[';Name';])) { $notify = $_POST[';Name';]; } <<<<< This closing bracket should be at the end. echo "Hello " . $_POST[';Name';]; // this is not set! echo "Hello " . $notify; //$notify is set } <<<<< Put bracket here ?>!
Re: Text book Chapter 5
September 11, 2013 10:00AM
Hi bigron11,

Thanks for the advise. It took away the notice error. Yay!!
But, my "Hello test" message is not showing.
It feels as if I am one step closer thanks to you guys.
Re: Text book Chapter 5
September 11, 2013 11:13AM
Hi there,

I have moved on to the next exercise in the textbook. And it worked 100%.
I think I am not going to waist more time on the first exercise, as my time is very limited and yours, so I thank each one of you for making an effort to assist me.smile
Re: Text book Chapter 5
September 11, 2013 11:13AM
Hi Zelda,

Move to page 145. Follow the instructions and create form3.php and formprocess3.php.
Use the code you've already written and add the extra. Your code will work!

Are you you using EasyPHP with Internet Explorer?

Charles U
Re: Text book Chapter 5
September 11, 2013 11:20AM
Hi Charles,

I have moved to form2, and it worked 100%. After the earlier comments I have changed from easyPHP to xampp with internet explorer. Both gave me the same error. But I am a happy chappy now that the form2 has worked!
Thanks for your help!!

Zelda
Re: Text book Chapter 5
September 11, 2013 11:21AM
Hi there,

The main thing is you've got it sorted. Well done!

I'm using EasyPHP with Firefox. Works like a dream.

CharlesU
avatar Re: Text book Chapter 5
September 11, 2013 11:29AM
In form1.php you are missing an opening < on your style tag.

Also, rather use consistent capitalization <Style></style> should be <style></style>


Windows ignores capitalization, Linux does not.

So, your script may work on your Windows computer, but will fail if you upload it to a Linux server - which most of the free ISP's are.
avatar Re: Text book Chapter 5
September 11, 2013 11:37AM
Have another look at your CSS in your <style></style> markup.

You are repeating some CSS, and setting 2 different colours for your TD element.
Re: Text book Chapter 5
September 11, 2013 12:19PM
Hi Bigron11,

I will have a look at that. I tend to do the different ways of caps and no caps. So that can be a problem that I created.
Thanks for your time. I will let you know if it fixed the error.

Zelda
avatar Re: Text book Chapter 5
September 11, 2013 12:53PM
The main problem is probably the opening < on the <style> tag.
It can affect all the following tags, including the <form> tag, until the end of the script.

You are also missing semi-colons at the end of 2 x CSS statements.
(Did post this earlier, but it seems to have got lost)
Re: Text book Chapter 5
September 11, 2013 03:18PM
Hi Bigron11,

I have made all the changes as suggested, (and an eye opener, of all my mistakes, thanks), but I am still getting the same error message.
I really don't know what this could be. I actually picked up the same error message in form3, and now it doesn't want to acknowledge formprocess3.php.
Form2 is the only one that works without error messages.
avatar Re: Text book Chapter 5
September 11, 2013 03:46PM
Don't know if this has anything to do with the problem -

You have set the <TD> tag styles in <style></style>, and then set them all again in the table itself. Lot of unnecessary repetition.
You have also set the font color to black, and then the background color to black as well. Nothing will be visible.
Re: Text book Chapter 5
September 11, 2013 03:54PM
This is directly out of the textbook. So I am not sure then.
It shows the table, and I can see everything clear.
The form3 is working fine now, but if I uncheck the debug button, I get the same error message as with form1.
So I am clueless at this stage.
But I appreciate all your input, you have shown me such a lot that I have missed.
avatar Re: Text book Chapter 5
September 11, 2013 06:00PM
Your code runs with no problems on my computer (WAMP).

I only made the changes suggested:
<style
; at end of 2 x CSS
Moved } in formprocess.

It seems therefore that the problem is not in your code, but in the system you are using.

Consider changing to WAMP, it does not have the problems that the other systems seem to have.
Re: Text book Chapter 5
September 11, 2013 07:38PM
Hi Zelda,

I think it's doing what it is supposed to.

I'm making a suggestion that might help you but just in case you think its cheating .....

Go to page 291 where the authors invite you to download their codes from the Web site www.wrox.com
The Chapters are all neatly laid out in folders with all the coded files you studying inside them.

I do the same as you, write in all my own code for practice purposes. If mine doesn't work I copy theirs
into a test file. If theirs runs and mine doesn't know I've made the mistake and it's not a computer problem.

CharlesU
Re: Text book Chapter 5
September 11, 2013 07:54PM
Hi Charles,

Thank you, I did just that, and I feel much more comfortable to check if I did anything wrong. But I must say, for some weird reason, mine worked, and I don't know what I did to be honest.smile
Thanks so much for the help and assistance.

Zelda
Re: Text book Chapter 5
September 11, 2013 08:15PM
And Bigron11,

Thanks for all your help, I did test it on xampp. I use both now because of this issue I picked up. But for some strange reason my code suddenly worked, and I don't know what changed.
So thanks again.
avatar
Mac
Re: Text book Chapter 5
September 12, 2013 08:17AM
bigron11 Wrote:
-------------------------------------------------------
>
Language: PHP
> <?php > if(isset($_POST[';Name';])) > { $notify = $_POST[';Name';]; } <<<<< This closing > bracket should be at the end. > echo "Hello " . $_POST[';Name';]; // this is not > set! > echo "Hello " . $notify; //$notify is set > } <<<<< Put bracket here > ?>! >

Oops... myself a bit too fast there smiling smiley Thanks goodness for another pair of eyes....
Re: Text book Chapter 5
September 16, 2013 01:09PM
Hi ,

Better late than never but I think we were sold unfinished teaser here!
I've put my solution on one page called form1.php for convenience.

Language: PHP
<html> <head> <title>Add/Search Entry</title> <?php if(isset($_POST[';Name';])) { $notify = $_POST[';Name';]; } else{ $notify=""; } ?>   <style type="text/css"> TD{color:#353535;font-family:verdana} TH{color:#FFFFFF;font-family:verdana;background-color:#336699} </style> </head> <body> <form action="form1.php" method="post"> <table border="0" cellspacing="1" cellpadding="3" bgcolor="#353535" align="center"> <tr> <td bgcolor="#FFFFFF" width="50%">Name</td> <td bgcolor="#FFFFFF" width="50%"> <input type="text" name="Name"> </td> </tr> <tr> <td bgcolor="#FFFFFF" colspan="2" align="center"> <input type="submit" NAME="SUBMIT" value="Submit"> </td> </tr> </table> <?php echo "Hello " . $notify; ?> <pre> DEBUG : <?php print_r($_POST); ?>   </form> </body> </html>
avatar
Mac
Re: Text book Chapter 5
September 16, 2013 04:05PM
Many hidden yeah, teasers many late nights - else we could have a MCQ smiling smiley And that is how you learn smiling smiley

That said, you test for a form submission, but if it is not true, where does it leave the user???
avatar Re: Text book Chapter 5
September 16, 2013 04:53PM
Where are you doing checks to prevent SQL injection? Remember you can not trust the input from the user.




78044545CharlesU Wrote:
-------------------------------------------------------
> Hi ,
>
> Better late than never but I think we were sold
> unfinished teaser here!
> I've put my solution on one page called form1.php
> for convenience.
>
>
Language: PHP
> <html> > <head> > <title>Add/Search Entry</title> > <?php > if(isset($_POST[';Name';])) > { $notify = $_POST[';Name';]; > } > else{ > $notify=""; > } > ?> > > <style type="text/css"> > TD{color:#353535;font-family:verdana} > TH{color:#FFFFFF;font-family:verdana;background-co > lor:#336699} > </style> > </head> > <body> > <form action="form1.php" method="post"> > <table border="0" cellspacing="1" cellpadding="3" > bgcolor="#353535" align="center"> > <tr> > <td bgcolor="#FFFFFF" width="50%">Name</td> > <td bgcolor="#FFFFFF" width="50%"> > <input type="text" name="Name"> > </td> > </tr> > <tr> > <td bgcolor="#FFFFFF" colspan="2" > align="center"> > <input type="submit" NAME="SUBMIT" > value="Submit"> > </td> > </tr> > </table> > <?php > echo "Hello " . $notify; > ?> > <pre> > DEBUG : > <?php > print_r($_POST); > ?> > > </form> > </body> > </html> >

___________________________________________________________________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning...
Re: Text book Chapter 5
September 16, 2013 06:57PM
Hi,

Glad you asked! Got a long way to go and not much time for research left. Stay with us,
some of us are going to need all the help we can get!

Regards CharlesU
Sorry, only registered users may post in this forum.

Click here to login