0

Hello dear community members,

I'm having issues inserting successfully into a little database I made. I'm trying to code a login using PHP to insert into the database directly. Here's the database code:

create table login (

id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
vorname VARCHAR (255) NOT NULL,
nachname VARCHAR (255) NOT NULL,
email VARCHAR (255) NOT NULL);

And here's my PHP code:

$link = mysqli_connect("localhost", "root", "", "projektmanagement");

// Check connection
                 if ($link === false) {
                     die("ERROR: Could not connect. " . mysqli_connect_error());
                 } else {
                     print "<h3>Connected!</h3>";
                 }
// Attempt insert query execution
                 $sql = "INSERT INTO login (username, password, vorname, nachname, email) VALUES ('Username', 'Password', 'Vorname', 'Nachname' 'peterparker@mail.com')";
                 if (mysqli_query($link, $sql)) {
                     echo "Records inserted successfully.";
                 } else {
                     echo "ERROR: Could not execute $sql. " . mysqli_error($link);
                 }

I have looked through countless threads, seeing if I miscounted or forgot a value, but I can't seem to find the mistake.

Any help would be greatly appreciated!

  • Thomas
  • 5
    You've forgotten comma (,) between 'Nachname' and 'peterparker@mail.com'. So this part of your code for MySQL is technically the same as 'Nachnamepeterparker@mail.com' -- one string value: https://dev.mysql.com/doc/refman/5.7/en/string-literals.html – fifonik Feb 20 '19 at 22:37
  • 1
    Also see [using password_hash that than plain text passwords](https://stackoverflow.com/questions/44470690/how-to-insert-data-into-database-using-pdo-registry-system/44470752#44470752) – danblack Feb 20 '19 at 22:48
  • I recommend using an SQL client as a side-tool to evaluate problematic queries. A good SQL client could detect and highlight such errors - suggest: MySQL Workbench or HeidiSQL. – Paperclip Feb 20 '19 at 22:53
  • This code might be a step up to SQL injection. Read up on php:pdo to protect your code from malicious use – Norbert Feb 20 '19 at 23:04

0 Answers0