/    Sign up×
Community /Pin to ProfileBookmark

hmm.. oh i see…. not!

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?

[URL]http://www.magicfrontier.com/temp/phptesting/listing7_3.php[/URL]

<html>
<head>
<title>Listing 7.3</title>
</head>
<body>

[code=php]<?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”);
?>[/code]

</body>
</html>

Thanks Coen

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@pyroDec 02.2003 — 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.
Copy linkTweet thisAlerts:
@hyperstyleauthorDec 03.2003 — 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.
Copy linkTweet thisAlerts:
@pyroDec 03.2003 — 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.
Copy linkTweet thisAlerts:
@hyperstyleauthorDec 03.2003 — 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.

[URL]http://www.magicfrontier.com/temp/phptesting/listing7_4.php[/URL]

<html>

<head>

<title>Listing 7.4</title>

</head>

<body>
[code=php]
<?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");
}
}
?>
[/code]

<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>
Copy linkTweet thisAlerts:
@pyroDec 03.2003 — 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:

[code=php]<?PHP
phpinfo();
?>[/code]

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).
Copy linkTweet thisAlerts:
@hyperstyleauthorDec 03.2003 — 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.
×

Success!

Help @hyperstyle spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...