0

The connection to the database works, but somehow the script doesn't write something in there. No Error-Message appears and the script also redirect me (in the last row) to danke.php.

Please take a look at this:

// validation
$valid = true;
if(
    empty ( $vorname ) ||
    empty ( $name ) ||
    empty ( $strasse ) ||
    empty ( $hausnr ) ||
    empty ( $plz ) ||
    empty ( $ort ) ||
    empty ( $email )
){
    $valid = false;
}

// database-connection
$db = mysqli_connect($db_server, $db_user, $db_password);
$db->select_db($db_name);

// send data
if($valid){
    $sql = "
    insert into 'bestellungen'
    (
    vorname, name, strasse, hausnr, plz, ort, email, bestelldatum
    )
    values
    (
    '". $vorname ."', '". $name ."', '". $strasse ."', '". $hausnr ."', '". $plz ."', '". $ort ."', '". $email ."', '". date('Y-m-d H:i:s') ."'
    )
    ";
    $db->query($sql);
    header('location: danke.php');
}

If you need more code, please tell me. Im totally frustrated :(

  • First, turn on error reporting and check both any PHP errors and any database errors. Second, you are wide open to [**SQL injection**](https://www.owasp.org/index.php/SQL_Injection). You need to use prepared statements. – elixenide Apr 16 '16 at 21:04

1 Answers1

0

Here,

 insert into 'bestellungen'

just remove the quotes around the table name:

 insert into bestellungen
CJ Nimes
  • 648
  • 7
  • 10