I have been searching days why this piece of code is not working. Adjusted the code multiple times by searching for posts with the same problem.
Problem: my php file doesn't seem to get the values it needs from a simple HTML form (made w. bootstrap) via POST-method. I use the issit function to check if the submit button has been clicked and thereafter I use to check if the form was filled out completely.
Please note that I am relatively new to php. I hope I did miss something and it is not just a simple typo.
PHP code (bootstrap/php/boeking.php)
<?php
//<!--debug-->
error_reporting(E_ALL);
ini_set('display_errors', '1');
//<!--connectie-->
mysql_connect("localhost","root","root") or die(mysql_error());
mysql_select_db("hota") or die(mysql_error());
//<!--boeking info verzenden-->
if(isset($_POST['send']))
{
if (isset($_POST['achternaam']))
{
$anaam = $_POST['achternaam'];
// do whatever here
}
if(isset($_POST['voornaam']))
{
$vnaam = $_POST['voornaam'];
}
}
$anaam = mysql_real_escape_string($anaam);
$vnaam = mysql_real_escape_string($vnaam);
$boek = "INSERT INTO klant (achternaam , voornaam) VALUES ('{$anaam}', '{$vnaam}')";
mysql_query($boek);
?>
HTML code:
<form id="newbook" method="POST" action="bootstrap/php/boeking.php" class="form-horizontal">
<legend>Nieuwe boeking</legend>
<div class="control-group">
<label class="control-label" for="voornaam">Voornaam</label>
<div class="controls">
<input type="text" name="voornaam" id="voornaam" placeholder="Voornaam">
</div>
</div>
<div class="control-group">
<label class="control-label" for="achternaam">Achternaam</label>
<div class="controls">
<input type="text" name="achternaam" id="achternaam" placeholder="Achternaam">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" name="send" class="btn">Sign in</button>
</div>
</div>
</form>
Thanks in advance!
UPDATE:
changed my php-code.
Not getting the undefined index error anymore.
Var_dump($vnaam); and var_dump($anaam); do indicate that strings are passed to the php but after that, when the query is fired, things don't seem to get send to the db.
Might this be a problem in my query ?
(already thanks for the tips: gave the button a value and used var_dump)
This is my new code :
<?php
//<!--debug-->
error_reporting(E_ALL);
ini_set('display_errors', '1');
//<!--connectie-->
mysql_connect("localhost","root","root") or die(mysql_error());
mysql_select_db("hota") or die(mysql_error());
$anaam = '';
$vnaam = '';
if(!isset($_POST['send'])) {
}
else
{
if (isset($_POST['achternaam']))
{
$anaam = $_POST['achternaam'];
// do whatever here
}
if(isset($_POST['voornaam']))
{
$vnaam = $_POST['voornaam'];
}
var_dump($vnaam);
var_dump($anaam);
$anaam = mysql_real_escape_string($anaam);
$vnaam = mysql_real_escape_string($vnaam);
}
var_dump($vnaam);
$boek = "INSERT INTO klant (achternaam , voornaam) VALUES ('{$anaam}', '{$vnaam}')";
mysql_query($boek);
?>
mysql_real_escape_string?mysql_escape_stringthat's slightly different.mysql_real_escape_stringis the one you should really use.