Click to See Complete Forum and Search --> : hmm.. oh i see.... not!
hyperstyle
12-02-2003, 07:01 AM
hi, I'm currently learning php. There is this exercise in my training book that i just can't get to work. I've copied it letter for letter just to make sure. What's ment to happen is once i submit the form it reloads the page and displays my choice. That's not happening. Is anyone able to help?
http://www.magicfrontier.com/temp/phptesting/listing7_3.php
<html>
<head>
<title>Listing 7.3</title>
</head>
<body>
<?php
// if not executed for first time;
if (isset($_REQUEST['part']))
{
print("<h3>Last Burger</h3>\n");
print("<u1>\n");
foreach($_REQUEST['part'] as $part)
{
print("<li>$part</li>\n");
}
print("</u1>\n");
}
$option=array("mustard", "ketchup", "pickles", "onions", "lettuce", "tomato");
print("<h3>Create a Burger</h3>\n");
print("<form action=\"{$HTTP_SERVER_VARS['PHP_SELF']}\">\n");
foreach($option as $o)
{
print("<input type=\"checkbox\" name=\"part[]\" value=\"$o\"> $o<br>\n");
}
print("<input type=\"submit\">\n");
print("</form>\n");
?>
</body>
</html>
Thanks Coen
The code worked fine for me, so I'm guessing you are using an old version of PHP. Try changing all instances of $_REQUEST to $HTTP_POST_VARS and set your forms method to post.
hyperstyle
12-02-2003, 06:02 PM
thanks, yeah that fixed it. My hosting is with hostsave.com. And it's verion 4 PHP. could it be that they have just configured it to use the old names.
It would have to be 4.1.0 or greater.
BTW, I used to use Hostsave for my hosting. Moved on to a reseller account at http://www.dr2.net/ and have been throughly satisfied.
hyperstyle
12-03-2003, 05:08 AM
I think i am having a similar problem with my next exercise. This script uploads a file and gives info on the upload. Originally it said to use $_FILES and that didn't work so i replaced it with $HTTP_FILES_VARS and it still doesn't work.
http://www.magicfrontier.com/temp/phptesting/listing7_4.php
<html>
<head>
<title>Listing 7.4</title>
</head>
<body>
<?php
//Check for file upload
if (isset($HTTP_FILES_VARS['upload_test']))
{
if($HTTP_FILES_VARS['upload_test']['error'] != UPLOAD_ERR_OK)
{
print("Upload unsucessful!<br>\n");
}
else
{
// delete this file
unlink($HTTP_FILES_VARS['upload_test']['tmp_name']);
// show information about the file
print("Local File: ".$HTTP_FILES_VARS['upload_test']['tmp_name']."<br>\n");
print("Name: ".$HTTP_FILES_VARS['upload_test']['name']."<br>\n");
print("Size: ".$HTTP_FILES_VARS['upload_test']['size']."<br>\n");
print("Type: ".$HTTP_FILES_VARS['upload_test']['type']."<br>\n");
print("<hr>\n");
}
}
?>
<form enctype="multipart/form-data" action="<?php print($HTTP_SERVER_VARS['PHP_SELF']); ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1024000">
<input name="upload_test" type="file">
<input type="submit" value="test upload">
</form>
</body>
</html>
I don't see anything there to actually upload the file. Take a look at http://us3.php.net/features.file-upload.
Also, you may want to run a phpinfo() script:
<?PHP
phpinfo();
?>
To check what version of PHP your server does support. If it really is less than 4.1.0 I'd recommend finding a new host if you plan to do any ammount of PHP work (or anyway, as PHP is free, so there's no excuse to not keep it current).
hyperstyle
12-03-2003, 05:42 PM
Yeah it was just the array name again. I ran that function and it's version 4. version 4 doesn't support upload errors either, so F$$% hostsave. I sent them an email yesterday suggesting they upgrade. If they don't reply i'll send a slightly more aggressive one. Then another, and anther. Until i reach the point where it would be less work just to change hosts.