/    Sign up×
Community /Pin to ProfileBookmark

$_GET change for $_POST

original code
<?php
echo “<form>
<input type=”number” name=”vcode”>
<input type=”submit”>
</form>”;
$vcode = $_GET[‘vcode’];
strlen($vcode);
if (strlen($vcode) == “18”)

i just want know if this is correct use of $_POST

<?php
echo “<form>
<input type=”number” name=”vcode”>
<input type=”submit”>
</form>”;
$vcode = $_POST[‘vcode’];
strlen($vcode);
if (strlen($vcode) == “18”)

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmFeb 07.2017 — 1 - please post code using the proper forum code tags (php & /php wrapped in square brackets)

2 - You obviously have not read anything on how to write or use html. Your form tag determines whether you will be using GET or POST. The default is GET so your first (bad) example would use $_GET when retrieving input

3 - Your 2nd example would not retrieve anything.

Your script is atrocious. So - it begins by outputting a form. And then it goes on to try and retrieve the input from that form. Have you thought about how that looks? It's like a one-sided conversation. You ask the question and then attempt to get the answer before the user evens reads it.

You apparently have never coded before or you would realize that your 6th line of code is meaningless. When trying to determine the length of something with a function call you need to either do it with an if statement or else save the returned value. You needlessly repeat your effort the proper way, although the comparison you are doing could be done simpler without the double quotes on the numeric value you are seeking since the returned value is a number, not a string.

You have a long way to go. I hope you decide to do some reading and learning rather than mindlessly grabbing other's code samples and trying them out without knowing anything about how they work. Good luck.
Copy linkTweet thisAlerts:
@NogDogFeb 07.2017 — Just a tip, you don't need everything to be inside of the <?php...?> tags, which can make typing plain old HTML easier:
[code=php]
<?php
// any preceding PHP stuff, then...
?>
<form action="" method="post">
<input type="number" name="vcode">
<input type="submit">
</form>
<?php
// let's avoid errors if vcode not yet submitted:
$vcode = isset($_POST['vcode']) ? $_POST['vcode'] : '';
if (strlen($vcode) == "18") {
// whatever goes on here?
}
[/code]
×

Success!

Help @bustercg 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.23,
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,
)...