/    Sign up×
Community /Pin to ProfileBookmark

Really simple PHP question

I made a script to take the users information they add into the text field “username” and print it to the page after hitting submit. Here’s my script:

[CODE]
<?php
if (($_POST[username] == “”) || ($_POST[password] == “”)) {
header(“Location: page1.html”);
exit;
}

else {
echo $_POST[username];
}
?>
[/CODE]

It doesn’t seem to work though.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@BoarsHellMar 16.2007 — Try this...

[code=php]if(!isset($_POST['username'])){
echo "username is not set";
if(strlen($_POST['username']) == 0){
echo "username has no characters";
}
}else{
echo "username is ".$_POST['username'];
}[/code]
Copy linkTweet thisAlerts:
@AscendancyauthorMar 16.2007 — Strange, that didn't work either...

Do you want me to post my form that I have?
Copy linkTweet thisAlerts:
@BoarsHellMar 16.2007 — Sure, post your form.

If you want to try a simple test with out using the form. Change the post variables to get variables in the script ($_POST change to $_GET) and then go to your php page and add the get variable to the url (ex. if you use the url like this... page1.php?$username=[COLOR="DarkRed"]tom[/COLOR] the script should print out a blank page with just the name tom)
Copy linkTweet thisAlerts:
@AscendancyauthorMar 16.2007 — I'm sorry, I don't follow what you mean... Haha. Well here is as basic as I could make it, and it still didn't work:

[CODE]
<form method="post" action="names.php">
<input type="text" name="username" length="20" />Username<br />
<br />
<input type="password" name="password" length="20" />Password<br />
<br />
<input type="submit" value="Submit" />
</form>
[/CODE]

Simple form. The password actually isn't used in this script yet. Then I changed my PHP page to this:

[CODE]
<html>
<head>
<title>Names</title>
</head>

<body>
<?php
ehco "$_POST[username]";
?>
</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@BoarsHellMar 16.2007 — you have a typo in names.php

you typed ehco and meant echo
Copy linkTweet thisAlerts:
@AscendancyauthorMar 17.2007 — Oh, I feel like an idiot. Haha, I'm sorry to waste your time, but thank you!
×

Success!

Help @Ascendancy 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.17,
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,
)...