I made a basic HTML form working with post (it's a login form). The form itself works great, but when I try to work with the information contained in $_POST it goes wrong.
<?php
// case : nothing submitted
if (!isset($_POST['submit'])) {
?>
<div class="login">
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Login</p>
<input type="text" id="username" placeholder="Username" name="username" />
<input type="password" id="password" placeholder="Password" name="password" />
<button name="submit">Submit</button>
</form>
</div>
<?php
// case : input form submitted
} else {
check_credentials();
}
?>
The problem is, it works fine when I do this ( above check_credentials()
: echo $_POST['username']; echo $_POST['password'];
But when I do this : echo $_POST['username'] + " " + $_POST['password'];
It echoes 0. As check_credentials()
is a function that connects to my DB, the request isn't executed. Does someone have any idea of the possible cause ?
Greetz !
You must use dots when concatenating in PHP. You probably "took" pluses from JS.
It should look like in this example:
<?php
$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"
$a = "Hello ";
$a .= "World!"; // now $a contains "Hello World!"
?>
And your example, if the variables are good:
echo $_POST['username']." ".$_POST['password'];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.