-2

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.

Gandalf
  • 1
  • 5
  • remove **,** in insert query – Abhishek Sharma Dec 01 '15 at 11:15
  • 3
    **Warning**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Dec 01 '15 at 11:17
  • You're testing to see if there are any errors when you connect to the database, but you aren't doing that when you try to run the query. Don't you think it might be useful to? – Quentin Dec 01 '15 at 11:18
  • deprecated functions again! Grrrr – rray Dec 01 '15 at 11:23
  • yea, i am a complete rookie at this so, i looked at your modern replacement but honestly i did not saw the difference – Gandalf Dec 01 '15 at 14:30

4 Answers4

0

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

Standej
  • 749
  • 1
  • 4
  • 11
0

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
    }
William Madede
  • 727
  • 4
  • 8
0

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

Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
Gandalf
  • 1
  • 5
0

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.

Ben
  • 759
  • 1
  • 6
  • 19
  • Whenever queries don't work you could try inputting raw SQL to the database to see if the SQL syntax is not broken. Also, when using variables in them it's good to check if the variables are defined correctly by echoing them before the query statement (although this would be hard if you run into a die() before getting to that echo) – Ben Dec 01 '15 at 12:02