0

I have some PHP and a HTML Form, two of the inputs are echoing fine the first input is not, and its something to do with the URL as when I remove the "+" from the fullname, the input then displays. Why is the url doing "+" and how can I fix it so the fullname input works

enter image description here

<div class="form-group">
<input id="fullname" name="fullname "type="text" class="form-control" placeholder="Full Legal Name">
</div>
<div class="form-group">
<input id="email" name="email" type="email" class="form-control" placeholder="Email Address">
</div>
<div class="form-group">
<input id="ContactNumber" name="ContactNumber" type="text" class="form-control" placeholder="Contact Number">
</div>


session_start();
if(!isset($_SESSION["staff"])){
header("Location: default.php");
exit(); }

$name = $_GET['fullname'];
$email = $_GET['email'];
$ContactNumber = $_GET['ContactNumber'];


echo $name. "</br>" . $email. "</br>" . $ContactNumber.
LIdbioe
  • 7
  • 3

1 Answers1

0

To answer your question:

The variable is there, but the + is a reserved sign in url encoding.

If you var_dump your $_GET superglobal, you'll get something like that:

array(1) { ["param_"]=> string(4) "test" }

If you want to use a plus in your variables, you have to use %2B because the + means whitespace in a URL. So if you want to pass hello world you'd be writing hello+world - just can't find a source for it because the RFC 3986 is a bit harsh to read.

So, the reason why your code fails is just a typo: "fullname " remove the whitespace...

For further information, just check out the Wikipedia article: https://en.wikipedia.org/wiki/Percent-encoding

Community
  • 1
  • 1
maio290
  • 6,440
  • 1
  • 21
  • 38