-1

I am making an site where a student can fill out an form and the answers will be stored in an database.

I made the php and it says it works but when i look at PhpMyAdmin it doesn't shows up.

What am I doing wrong?

I hope you can help me.

PHP File:

    <?php
$dbHost = "localhost";          //Location Of Database - usually it's "localhost" 
$dbUser = "root";               //Database User Name 
$dbPass = "";                   //Database Password 
$dbDatabase = "hr";             //Database Name 
$naam = $_POST['name'];         //Name User
$naam2 = $_POST['name2'];
$naamtbl = $naam."_beoor_".$naam2;
$date = date("Y-m-d H:i");

echo($date."<br/>");

//get answers
$C_KVW = $_POST['cijfer_KVW'];
$TL_KVW = $_POST['TL_KVW'];
$C_AW = $_POST['cijfer_AW'];
$TL_AW = $_POST['TL_AW'];
$C_FB = $_POST['cijfer_FB'];
$TL_FB = $_POST['TL_FB'];
$C_WC = $_POST['cijfer_WC'];
$TL_WC = $_POST['TL_WC'];
$C_ST = $_POST['cijfer_ST'];
$TL_ST = $_POST['TL_ST'];
$C_CF = $_POST['cijfer_CF'];
$TL_CF = $_POST['TL_CF'];
$C_OP = $_POST['cijfer_OP'];
$TL_OP = $_POST['TL_OP'];
$C_IN = $_POST['cijfer_IN'];
$TL_IN = $_POST['TL_IN'];
$C_NA = $_POST['cijfer_NA'];
$TL_NA = $_POST['TL_NA'];
$C_OB = $_POST['cijfer_OB'];
$TL_OB = $_POST['TL_OB'];

$db = mysql_connect($dbHost,$dbUser,$dbPass)or die("Error connecting to database!"); 
mysql_select_db($dbDatabase, $db)or die("Couldn't select the database!");
$sql = "CREATE TABLE $naamtbl( ".
   "id INT NOT NULL AUTO_INCREMENT, ".
   "naam_filler VARCHAR(20) NOT NULL, ".
   "naam VARCHAR(20) NOT NULL, ".
   "cijfer_KVW VARCHAR(20) NOT NULL, ".
   "TL_KVW VARCHAR(20) NOT NULL, ".
   "cijfer_AW VARCHAR(20) NOT NULL, ".
   "TL_AW VARCHAR(20) NOT NULL, ".
   "cijfer_FB VARCHAR(20) NOT NULL, ".
   "TL_FB VARCHAR(20) NOT NULL, ".
   "cijfer_FO VARCHAR(20) NOT NULL, ".
   "TL_FO VARCHAR(20) NOT NULL, ".
   "cijfer_SW VARCHAR(20) NOT NULL, ".
   "TL_SW VARCHAR(20) NOT NULL, ".
   "cijfer_WC VARCHAR(20) NOT NULL, ".
   "TL_WC VARCHAR(20) NOT NULL, ".
   "cijfer_ST VARCHAR(20) NOT NULL, ".
   "TL_ST VARCHAR(20) NOT NULL, ".
   "cijfer_CF VARCHAR(20) NOT NULL, ".
   "TL_CF VARCHAR(20) NOT NULL, ".
   "cijfer_OP VARCHAR(20) NOT NULL, ".
   "TL_OP VARCHAR(20) NOT NULL, ".
   "cijfer_IN VARCHAR(20) NOT NULL, ".
   "TL_IN VARCHAR(20) NOT NULL, ".
   "cijfer_NA VARCHAR(20) NOT NULL, ".
   "TL_NA VARCHAR(20) NOT NULL, ".
   "cijfer_OB VARCHAR(20) NOT NULL, ".
   "TL_OB VARCHAR(20) NOT NULL, ".
   "date_time DATE, ".
   "PRIMARY KEY ( id )); ";
if($sql){
    echo("Gelukt");
}else{
    echo("Error");
}
    ?>
yolo-lol
  • 11
  • 4

3 Answers3

1

The reason nothing changes in your database, is that you are just setting a string containing a - very risky and sql injection open - query but you do not actually execute the query.

But there is really no reason to make a new table for every student if all columns are the same all the time. Just add a column with the name, or better, an ID that links to another table that contains the names and make the table once.

And you should switch to a more modern (non-deprecated...) database interface like PDO or mysqli that will allow you to use prepared statements.

jeroen
  • 91,079
  • 21
  • 114
  • 132
0

Try running this before the "IF" statement:

mysql_query("CREATE DATABASE hr") or die(mysql_error());
mysql_query($sql) or die(mysql_error());

Now you don't need the if, because if there was an error "die(mysql_error())" will stop the script and output it.

Kristian Lilov
  • 610
  • 6
  • 12
0

The problem is that you are not executing the sql therefore you dont see the table in your database:

if(mysql_query($sql)){   
    echo("Gelukt");
}else{
    echo("Error:". mysql_error());
}

BTW mysql functions are deprecated and I suggest you to start using mysqli Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
talsibony
  • 8,448
  • 6
  • 47
  • 46