...

View Full Version : Resolved newbee problem



adarshakb
10-18-2009, 07:19 PM
Hi i am new to php and was practising loops from the tutorial site http://devzone.zend.com/node/view/id/635
But i got into a problemwhen i run my code
Why does the following error message come?

Forbidden

You don't have permission to access /TestSite/method="post" on this server.
Apache/2.0.63 (Win32) PHP/5.2.11 Server at localhost Port 80
i cant figure it out.. The other programs use the same "POST" method to get their variables but why does this program return an error? If i run the tutorial code whch uses the same post method it works but not mine
please help me
i did the coding and here is my code



<head>
<title>Untitled Document</title>
</head>

<body>

<form action=<?php $_SERVER['PHP_SELF'] ?> method="post">
Enter the number of Rows <input name="rows" type="text" value="3" /> and Coloumn <input name="coloumn" type="text" value="3" /> <input name="submit" type="submit" value="submit" /></form>

<?php

if (isset($_POST['submit'])) {
echo "<table width = 90% border = '1' cellspacing = '5' cellpadding = '0'>";
for ($r = 1; $r <= $_POST['rows']; $r++) {
echo "<tr>";
for ($c = 1; $c <= $_POST['columns'];$c++) {
echo "<td>&nbsp;</td> ";
} echo "</tr> ";
}
echo "</table> ";
}

?>
</body>
</html>
here is the tutorials code
<html>
<head></head>
<body>

<?php
// check for submit
if (!isset($_POST['submit'])) {
// and display form
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="artist[]" value="Bon Jovi">Bon Jovi
<input type="checkbox" name="artist[]" value="N'Sync">N'Sync
<input type="checkbox" name="artist[]" value="Boyzone">Boyzone
<input type="checkbox" name="artist[]" value="Britney Spears">Britney Spears
<input type="checkbox" name="artist[]" value="Jethro Tull">Jethro Tull
<input type="checkbox" name="artist[]" value="Crosby, Stills & Nash">Crosby, Stills & Nash
<input type="submit" name="submit" value="Select">
</form>

<?php
}
else {
// or display the selected artists
// use a foreach loop to read and display array elements
if (is_array($_POST['artist'])) {
echo 'You selected: <br />';
foreach ($_POST['artist'] as $a) {
echo "<i>$a</i><br />";
}
}
else {
echo 'Nothing selected';
}
}
?>

</body>
</html>

karlosio
10-18-2009, 08:24 PM
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

Your missing the echo function, plus you don't have quotes around the action attribute neither. That could be it?

adarshakb
10-19-2009, 07:24 AM
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

Your missing the echo function, plus you don't have quotes around the action attribute neither. That could be it?

yep that was the problem :) but got a new problem after i fixed that one .. misspelled coloumn
thanks

karlosio
10-19-2009, 10:23 PM
yep that was the problem :) but got a new problem after i fixed that one .. misspelled coloumn
thanks

Yep thats due to this line



Enter the number of Rows <input name="rows" type="text" value="3" /> and Coloumn <input name="coloumn" type="text" value="3" /> <input name="submit" type="submit" value="submit" /></form>


In you haven't figured it, It should be:



Enter the number of Rows <input name="rows" type="text" value="3" /> and Coloumn <input name="columns" type="text" value="3" /> <input name="submit" type="submit" value="submit" /></form>


if you look in the PHP script you will see the following variables known as POST superglobals



$_POST['rows'];
$_POST['columns'];


These POST superglobals are getting whatever is posted to the server via the HTML form, its looking for the field names in the form under name="field" and places them inside a array so you access it via PHP eg $_POST['field'] (field name in square brackets with quotes) and these names have to be exactly the same as what is in the name attribute on the form. Hope that helps. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum