Welcome! Log In Create A New Profile

Advanced

Topic 2C

Posted by Anonymous User 
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
Anonymous User
Topic 2C
January 16, 2006 08:21AM
This is the thread for problems/comments related to Topic 2C.
Re: Topic 2C
February 21, 2006 08:21AM
This topic is completed, no problems.
Re: Topic 2C
February 28, 2006 09:45AM
Hi
well I am not managing with the task 2c1

I assume it it the GET vs POST command yet again, but I still do not get it working.

in the html file I use
<form method='POST' action='function.php'> (where function.php is the file name of the file being called.


in the .php file I am lost
I have tried a few different options, but I am guessing and this is not the correct way.



when I run the html file I get the option to open or save the php file


Re: Topic 2C
March 04, 2006 06:18PM
I am also having problems. I changed the form to post and added
$cost=$_POST['cost']; above the function and it just returns an answer of zero.
avatar
Mac
Re: Topic 2C
March 06, 2006 07:54AM
This is much simpler code for 2c-1. Change method to post in cost.html

<?php
$price=$_POST['price'];
$items=$_POST['items'];

function total($price, $items)
{
$cost=$price* $items;
echo "the total price is $$cost";
}

echo total($price,$items);
?>

libby - $cost=$_POST['cost']; is not going to bring you anywhere - cost was not passsed from cost.html to functions.php.
price and items were.

Note: the $ meant as a dollar as here above could cause problems. Better to print it outside php, like:

<?php
$price=$_POST['price'];
$items=$_POST['items'];

function total($price, $items)
{
$cost=$price* $items;echo "the total price is"; ?>$<?php echo "$cost";}

echo total($price,$items);
?>





Re: Topic 2C
March 06, 2006 08:27AM
I have also now copleted this section

one question

why does php NOT simply ignore all that is placed between /*




*/


if I place valid code as comments it tries to interpret this, it gave me an error said it could not redefine a variable, and when I placed // in front of that line (all still inside /* */)

it gave me a different output
Re: Topic 2C
March 06, 2006 08:43AM
Check you code. Make sure you don't have a */ before the last one you want to use. PHP check for the first */ it find. I have made this error a few times. The rule is, nested comments will not work. winking smiley
avatar
Mac
Re: Topic 2C
March 06, 2006 08:46AM
If I do this:

/*
echo total($price,$items);
*/

or this

/*
// echo total($price,$items);
*/
or this

// echo total($price,$items);


it WILL not, CANNOT, and SHALL not parse the code. There is no way it can! Whether its valid code or not does not matter. You can put your dog in there and PHP will ignore it....

the // inside the /* */ is irrelevant since it is not parsed in any event.




Re: Topic 2C
March 06, 2006 10:04AM
well I would like to agree but my software is influenced by what it in the comments, so much so that I removed the comments, which I consider bad programming practice
avatar
Mac
Re: Topic 2C
March 06, 2006 11:16AM
Quite right about removing comments. It helps you to remember exactly what you were thinking when looking at this code a year or more down the road. Never remove or not use comments.

/*
echo "this is amazing";
*/


If the above is shown in the browser window when you call the page it appears in, assuming apache is running and parsing your code, then I am at a loss for words.
Sorry, you do not have permission to post/reply in this forum.