Igzo Igzo - 4 months ago 15
HTML Question

Data in not being sent to database

I'm learning to code web pages and I tumbled into a problem which don't know how to fix it. I think I did everything well, but it doesn't send data to the server. I bought an html template, and I'm working on it. When I modified the action in the form tag it didn't send data. This is my html form(full page here):

<form action="includes/registerhandler.php" method="POST" role="form" id="form_register" enctype="multipart/form-data">

<!--<div class="form-register-success">
<i class="entypo-check"></i>
<h3>You have been successfully registered.</h3>
<p>We have emailed you the confirmation link for your account.</p>
</div>-->

<div class="form-steps">

<div class="step current" id="step-1">

<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="entypo-user"></i>
</div>

<input type="text" class="form-control" name="FullName" id="name" placeholder="Full Name" autocomplete="off" />
</div>
</div>

<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="entypo-phone"></i>
</div>

<input type="text" class="form-control" name="Phone" id="phone" placeholder="Phone Number" data-mask="phone" autocomplete="off" />
</div>
</div>

<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="entypo-calendar"></i>
</div>

<input type="text" class="form-control" name="B-D" id="birthdate" placeholder="Date of Birth (DD/MM/YYYY)" data-mask="date" autocomplete="off" />
</div>
</div>

<div class="form-group">
<button type="button" data-step="step-2" class="btn btn-primary btn-block btn-login">
<i class="entypo-right-open-mini"></i>
Next Step
</button>
</div>

<div class="form-group">
Step 1 of 2
</div>

</div>

<div class="step" id="step-2">

<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="entypo-user-add"></i>
</div>

<input type="text" class="form-control" name="UserName" id="username" placeholder="Username" data-mask="[a-zA-Z0-1\.]+" data-is-regex="true" autocomplete="off" />
</div>
</div>

<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="entypo-mail"></i>
</div>

<input type="text" class="form-control" name="Email" id="email" data-mask="email" placeholder="E-mail" autocomplete="off" />
</div>
</div>

<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="entypo-lock"></i>
</div>

<input type="password" class="form-control" name="PassWord" id="password" placeholder="Choose Password" autocomplete="off" />
</div>
</div>

<div class="form-group">
<button type="submit" class="btn btn-success btn-block btn-login">
<i class="entypo-right-open-mini"></i>
Complete Registration
</button>
</div>

<div class="form-group">
Step 2 of 2
</div>

</div>

</div>

</form>


And this is my PHP script:

<?php
include 'connect.php';

if(isset($_POST)){
$FullName = $_POST['FullName'];
$UserName = $_POST['UserName'];
$B-D = $_POST['B-D'];
$Gender = $_POST['Gender'];
$Address = $_POST['Address'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];
$City = $_POST['City'];
$Country = $_POST['Country'];
$PassWord = $_POST['PassWord'];

$repons = $bdd->query('select count(*) from user where Username =\'' .$UserName. '\'')->fetchColumn();

if($repons == 1){
echo 'user already exist';
}
else{
$req = $bdd->prepare('INSERT INTO user VALUES ("",:UserName,:PassWord,:B-D,:Email,:FullName,:Phone,:Gender,:Address,:City,:Country)');
$req->execute(
array( ':FullName' => $FullName, ':UserName' => $UserName, ':B-D' => $BirthDate, ':Gender' => $Gender, ':Phone' => $Phone, ':Email' => $Email, ':City' => $City, ':Country' => $Country, ':PassWord' => $PassWord, ':Address' => $Address));

$idp = $bdd->lastInsertId();

echo 'you are now a member confirmation email sent';
}
else{
echo 'submit is not set';
}



?>


I add a session variable to test if the file has been executed but it still didn't show a thing.

Answer

In PHP variables are case sensitive. And unless I'm mistaken the native PHP session variable is $_SESSION. So if that is your exact PHP code above and all you want it to do is increment the value of key 'var' then you need to use the $_SESSION['var'].

It would look more like this.

session_start();
if(isset($_SESSION['var']))
{
    $_SESSION['var']++;
}
else
{
    $_SESSION['var'] = 0;
}

And of course to test that the PHP script is increasing the key value properly then you need to output $_SESSION['var'] or some other indication to the client side, or text file, etc.

You must have been editing your question as I was posting my answer. But I would change your last PHP line to:

echo $_SESSION['var'];

?>

Just so that your output is more relevant and helpful.

I would leave this in a comment, however I don't have enough reputation points. Reading your further comments on your question it may be helpful to check if your PHP script is being run at all. I would check the network tab of Chrome's developer tools to see if you are finding the correct script and what errors are being returned.