0

I'm not sure why it's not inserting any data. No errors are returned.

I'm new in the mysql scene so i might be doing something wrong..

Do you guys mind pointing me towards the right direction?

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

    if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}


else if ($command == 'create-key'){

  $keys = $_GET['nkey'];

    if (empty($_GET['nkey'])){
      print('Error: No key specified to create!');
      die();
    }

    print ('Key '. $_GET['nkey'] .' has been created.');

    $sql = ("INSERT INTO `keys` (`key`, `status`) VALUES ('. $keys .', 0)");

}

SQL Code:

CREATE TABLE `keys` (
  `key` varchar(15) NOT NULL,
  `status` int(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Rayan
  • 1
  • 1

2 Answers2

1

There is no need of ()

Change Query From

$sql = ("INSERT INTO `keys` (`key`, `status`) VALUES ('. $keys .', 0)");

To

$sql = "INSERT INTO `keys` (`key`, `status`) VALUES ('$keys', 0)";

And then Execute this Query

TarangP
  • 2,711
  • 5
  • 20
  • 41
1

You'll probably need this on top of your script to see PHP errors:

<?php
ini_set('display_errors', 'on');
error_reporting ( E_ALL );

To help you with your error, have a look at your query.

$sql = ("INSERT INTO `keys` (`key`, `status`) VALUES ('. $keys .', 0)");

While this is should insert . $keys . in your table, please try:

$sql = ("INSERT INTO `keys` (`key`, `status`) VALUES ('". $keys ."', 0)");
Scriptman
  • 424
  • 2
  • 13