0

The form created shows the data being sent within the URL when the submit is clicked however the only part which is sent to the server is the username/$un. All of form inputs are being ignored.

HTML Form:

<form action="CharacterAdd.php">
<legend>Add Character</legend>
Character Name:<br>
<input type="text" name="Name" >
<br>
Gender:<br>
<input type="text" name="Gender" >
<br>
Age:<br>
<input type="text" name="Age" >
<br>
Hobbies:<br>
<input type="text" name="Hobby" >
<br>
Home:<br>
<input type="text" name="Home" >
<br>
Job:<br>
<input type="text" name="Job" >
<br>
<input type="submit" value="Submit">
<p>
<br>
</form>

PHP Code:

$un = $_SESSION["gatekeeper"];

$a = htmlentities($_POST['Name']);
$b = htmlentities($_POST['Gender']);
$c = htmlentities($_POST['Age']);
$d = htmlentities($_POST['Hobby']);
$e = htmlentities($_POST['Home']);
$f = htmlentities($_POST['Job']);
$g = htmlentities($_POST['$un']);

{
    $statement = $conn->prepare("INSERT INTO Characters(Name,Gender,Age,Hobby,Home,Job,username) VALUES (?,?,?,?,?,?,?)");
    $statement->bindParam(1,$a);
    $statement->bindParam(2,$b);
    $statement->bindParam(3,$c);
    $statement->bindParam(4,$d);
    $statement->bindParam(5,$e);
    $statement->bindParam(6,$f);
    $statement->bindParam(7,$un);
    $statement->execute();
    $conn->query ($charac);
Will
  • 45
  • 1
  • 7

3 Answers3

2

If you want to send the form with POST, change the method, as the default is GET

<form action="CharacterAdd.php" method="POST">

or you could check the $_GET superglobal instead

$a = htmlentities($_GET['Name']);
$b = htmlentities($_GET['Gender']);
adeneo
  • 312,895
  • 29
  • 395
  • 388
1

please declare method="POST" in form tag.

0

You might be wrapping your PHP code like:

if(isset($_POST['submit'])){
  ...
}

Which is a common mistake among developers, because in order for that to work, you need to name your submit button as submit like <input name="submit" value="Submit form">. Also, you need to set some form attributes, such as the method and action. The default method is get. If you want your values hidden from the browser address bar, make sure you set your method to post like <form method="post">. You also need to specify a file that will be called usingaction`. If not set, the file within which the form is is taken as the action.

Supreme Dolphin
  • 2,248
  • 1
  • 14
  • 23