Today i have run into some problems with mysql, php and html.
So i have a database called "gebruikers" in that database i have a table called "registratie" and i use USBwebserver V8.6 for the hosting
i have made a form for people to register them for the website i am planning to make, but what i'm bumping into is that when i press "inschrijven" it won't insert the data typed in the form into my database i have looked on stackoverflow but i couldn't find the solving answer to my problem.
PHP:
<?php
session_start();
include_once 'dbconnect.php';
$gebruikersnaam = mysql_real_escape_string($post['gebruikersnaam']);
$wachtwoord = mysql_real_escape_string($post['wachtwoord']);
$voornaam = mysql_real_escape_string($post['voornaam']);
$tussenvoegsel = mysql_real_escape_string($post['tussenvoegsel']);
$achternaam = mysql_real_escape_string($post['achternaam']);
$klas = mysql_real_escape_string($post['klas']);
$telefoon = mysql_real_escape_string($spot['telefoon']);
$geboortedatum = mysql_real_escape_string($post['geboortedatum']);
$email = mysql_real_escape_string($post['email']);
$geslacht = mysql_real_escape_string($post['geslacht']);
if(mysql_query("INSERT INTO gebruikers(gebruikersnaam,) VALUES('$gebruikersnaam')"
?>
HTML:
<body>
<div id=titel>
<a href=index.html><img src="images/logo.jpg" alt="Homepage"id=logo></a>
Registratie
</div>
<div id=registratie>
form method="post">
Gebruikersnaam:
<input type="text" name="gebruikersnaam">
<br>
<br>
Wachtwoord:
<input type="password" name="wachtwoord">
<br>
<br>
Voornaam:
<input type="text" name="voornaam">
<br>
<br>
Tussenvoegsel:
<input type="text"name="tussenvoegsel">
<br>
<br>
Achternaam:
<input type="text" name="achternaam">
<br>
<br>
Klas:
<input type="text" name="klas">
<br>
<br>
Telefoon:
<input type="tel" name="telefoon">
<br>
<br>
Geboortedatum:
<input type="date" name="geboortedatum">
<br>
<br>
Email:
<input type="email" name="email">
<br>
<br>
Geslacht:
<br>
<select>
<option value="Man">Man</option>
<option value="Vrouw">Vrouw</option>
</select>
<br>
<br>
<input type="submit" onclick="alert('Registratie voltooid')" value="Inschrijven">
</form>
<a href=index.html id="button">Terug naar hoofdpagina</a>
</div>
</body>
i really hope that this can help you guys out. this is my DBCONNECT.PHP:
<?php
if(!mysql_connect("localhost", "root", "usbw", "gebruikers"))
{
die('connection problem.' .mysql_error());
}
if(!mysql_select_db("gebruikers"))
{
die('No database selected' .mysql_error());
}
include
?>
i really hope you guys could help me out, because i'm out of ideas how i can fix this problem and i don't know where my problem lies.
NOTE: some words are in dutch.
You having mistake here
if(mysql_query("INSERT INTO gebruikers(gebruikersnaam,) VALUES('$gebruikersnaam')"
It should be like
if(mysql_query("INSERT INTO gebruikers(gebruikersnaam) VALUES('$gebruikersnaam')")){
// if true do some stuff if you need
}
?>
so in your query you have extra comma (,) then missing closing brackets and at the end you missing if brackets if you need to do some operations in it
Change
if(mysql_query("INSERT INTO gebruikers(gebruikersnaam,) VALUES('$gebruikersnaam')"
to
$insert=mysql_query("INSERT INTO gebruikers(gebruikersnaam,) VALUES('$gebruikersnaam')") or die(mysql_error());
if($insert){
//do your stuff
}
You having mistake here
if(mysql_query("INSERT INTO gebruikers(gebruikersnaam,)
VALUES('$gebruikersnaam')"
It should be like
if(mysql_query("INSERT INTO gebruikers(gebruikersnaam)
VALUES('$gebruikersnaam')"){}
?>
i've replaced my code with yours, but it still won't insert the data i typed in the form into the database, thanks for thinking with me. appreciating
You're not calling the POST variables correctly.
$gebruikersnaam = mysql_real_escape_string($post['gebruikersnaam']);
Should be:
$gebruikersnaam = mysql_real_escape_string($_POST['gebruikersnaam']);
Also, it's a bad habit to throw die() functions for minor things like database handling since this kills the rest of the page's functionality.