-3

So, while I was trying to get some data into my database, I came across this problem, of which I have no clue how to fix it. It just gives no output at all. I am a total newbie to php and database registering. I am able to do some sql.

Also, while I was testing some stuff I came to the conclusion that when I have a small database(just user, email and password) I am able to insert some data into the database. That's why I made two separate databases.

Info about the db: - Called datingsite - two tables: 'User' and 'Eigenschappen' - Both tables have a 'Lidnummer'(INT. Max 255) and set to index and AI

I am using portable xampp 1.8.3

Code:

Connect.php:

<?php
$connection = mysqli_connect('localhost', 'root', '');
if (!$connection){
    die("Database Connection Failed" . mysql_error());
}
$select_db = mysqli_select_db($connection,'datingsite');
if (!$select_db){
    die("Database Selection Failed" . mysql_error());
}
?>

Register.php:

<?php
    require('connect.php');
    /* If the values are posted, insert them into the database.
        $sql = "SELECT * FROM `user`";
        $res = mysql_query($sql);
        $row = mysql_fetch_array($res) or die(mysql_error());
        echo $row['email']. " - ". $row['wachtwoord'];*/

    if (isset($_POST['email']) && isset($_POST['wachtwoord'])){
        $email = $_POST['email'];       
        $wachtwoord = $_POST['wachtwoord'];
        $Voornaam = $_POST['Voornaam'];
        $Tweedenaam = $_POST['Tweedenaam'];
        $Achternaam = $_POST['Achternaam'];     
        $Ben = $_POST['Ben'];
        $Zoek = $_POST['Zoek'];     

        $Woonplaats = $_POST['Woonplaats'];
        $Provincie = $_POST['Provincie'];
        $Hobby1 = $_POST['Hobby1'];
        $Hobby2 = $_POST['Hobby2'];
        $Dag = $_POST['Dag'];
        $Maand = $_POST['Maand'];
        $Jaar = $_POST['Jaar'];
        $Opleiding = $_POST['Opleiding'];

        $query = "INSERT INTO 'user' ('Email', 'Wachtwoord', 'Voornaam', 'Tweedenaam', 'Achternaam', 'Ben', 'Zoek', 'Ingelogd') 
        VALUES (
            '$email', 
            '$wachtwoord', 
            '$Voornaam', 
            '$Tweedenaam', 
            '$Achternaam',  
            '$Ben', 
            '$Zoek')";
        $query2 = "INSERT INTO  'Eigenschappen' ('Woonplaats', 'Provincie', 'Hobby1', 'Hobby2', 'Dag', 'Maand', 'Jaar', 'Opleiding')
        VALUES (
            '$Woonplaats', 
            '$Provincie', 
            '$Hobby1', 
            '$Hobby2', 
            '$Dag', 
            '$Maand', 
            '$Jaar', 
            '$Opleiding')";
        $result = mysql_query($query);
        $res = mysql_query($query2);
        if(($result)&($res)){
            $msg = "User Created Successfully.";
        }
    }
    ?>


<!DOCTYPE html>
<html lang="nl">
<head>

<meta charset="utf-8" />

<title>Registreren op Chives</title>
<link href="../Css/inlog.css" rel="stylesheet"/>
<link href="../Css/styles.css" rel="stylesheet" />






</head>

<body class="back">
    <?php
    if(isset($msg) & !empty($msg)){
        echo $msg;
    }
 ?> 

<div id="Inlog-Container" align="center">
<form action="" method="post">


    <H1> Registreren </H1>
    <H2> Email:</H2>
    <input name="email" type="email" class="Input-box" required/>
    <H2> Wachtwoord:</H2>
    <input name="wachtwoord" type="password" class="Input-box"  required/>
<div class="Radiolabelbox">
    <fieldset class="" id="" >

                  <H2>Ik ben een:</H2>

                  <div class="Radiolabel">  
                    <label>
                      <input type="radio" name="Ben" class="styled-radio" value="Man" required/>
                        Man
                    </label> <br />

                    <label>
                        <input type="radio" name="Ben" class="styled-radio" value="Vrouw"/>
                        Vrouw                
                    </label>
                   </div>
                </fieldset>
                <fieldset class="">

                  <H2 class="">Ik zoek een:</H2>

                  <div class="Radiolabel">
                      <label>
                        <input type="radio" name="Zoek" class="styled-radio" value="Man" required/>
                        Man
                    </label> 
                    <br />

                      <label>
                        <input type="radio" name="Zoek" class="styled-radio" value="Vrouw"/>
                        Vrouw   
                    </label> 
                      <br />

                    <label>
                        <input type="radio" name="Zoek" class="styled-radio" value="Beide"/>
                        Beide
                    </label>
                  </div>
                </fieldset>
      </div>
    <H2> Woonplaats:</H2>
    <input name="Woonplaats" type="text" class="Input-box"  required/>
    <H2> Provincie:</H2>
    <input name="Provincie" type="text" class="Input-box"  required/>
    <H2> Hobby 1:</H2>
    <input name="Hobby1" type="text" class="Input-box"  required/>
    <H2> Hobby 2:</H2>
    <input name="Hobby2" type="text" class="Input-box"  required/>
    <H2> Voornaam:</H2>
    <input name="Voornaam" type="text" class="Input-box"  required/>
    <H2> Tweede naam:</H2>
    <input name="Tweedenaam" type="text" class="Input-box"  required/>
    <H2> Achternaam:</H2>
    <input name="Achternaam" type="text" class="Input-box"  required/>
    <H2> Geboortedag:</H2>
    <input name="Dag" type="Number" class="Input-box" min="0" max="31" required/>
    <H2> Geboortemaand:</H2>
    <input name="Maand" type="Number" class="Input-box" min="0" max="12" required/>
    <H2> Geboortejaar:</H2>
    <input name="Jaar" type="Number" class="Input-box" min="1920" max="2000" required/>
    <H2> Opleiding:</H2>
    <input name="Opleiding" type="Text" class="Input-box"  required/>    

    <input type="submit" value="GA VERDER" class="Roundbutton" id="Login" />
</form>
</div>



</body>
</html>

How can I get to fix my code so I can register into my database?

Any help is appreciated! Thanks in advance!

Ps. I'm sorry for the fact that most of the text in my code is in dutch.

Evochrome
  • 1,205
  • 1
  • 7
  • 20
  • **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 Jan 24 '15 at 17:19
  • After you try to connect to the database, you call `mysql_error` to see if there are any problems. You don't do that after trying to query the database. You need to. – Quentin Jan 24 '15 at 17:20
  • @Quentin The reason I use an old version of xampp is that my teacher told me to use an old version of xampp, so there would be less bug etc. Nevertheless, thank you for your help. I have added mysql_error. Now it doesn't give any error except for my error message 'Database Insert Failed'. – Evochrome Jan 24 '15 at 18:05
  • `mysqli_` was introduced in PHP 5.0. It's been almost a decade since they made a version of PHP which didn't support it. You are already using it in *part* of your code. You are not using a version of XAMPP that is too old to support it. – Quentin Jan 24 '15 at 18:07
  • Nothing in the code you've shared so far will output "Database Insert Failed". Presumably you've updated it to use `mysql_error` but you haven't looked at the output from the error checking function. – Quentin Jan 24 '15 at 18:08
  • It gives that output, after I have added that, according to your first comment. – Evochrome Jan 25 '15 at 02:07

3 Answers3

1

Multiple problems seems in your code:

you are opening a mysqli_connection and using mysql_

$result = mysql_query($query); to run query. That is wrong.

It must be

$result = mysqli_query($connection, $query);

same for

$res = mysql_query($query2);

must be

$res = mysqli_query($connection, $query2);

php mysqli query : http://php.net/manual/en/mysqli.query.php

Check Procedural style in the above link for executing a php mysqli query.

Next:

You dont need ' (quotes) between your table field names when calling an insert query.

But your insert query contains quotes.

Please refer http://www.w3schools.com/php/php_mysql_insert.asp for php mysql insert statement.

Next:

Error in using AND operator

if(($result) & ($res))

Must be

if(($result) && ($res))

(Pointed out be Moid Mohd in his answer)

fortune
  • 3,361
  • 1
  • 20
  • 30
1

First of all in insert statement use quotes only for text data, number don't need them, and neither table name need them In if statement if(($result)&($res)) you are using bitwise operator rather you should use if(($result) && ($res)). Similarly if(isset($msg) & !empty($msg)) here. It should be if(isset($msg) && !empty($msg))

Moid
  • 1,447
  • 1
  • 13
  • 24
1

You have error in your first insert query.You mentioned eight columns but insert only seven values.

Please check and correct it.

Debug Diva
  • 26,058
  • 13
  • 70
  • 123