duan1982453 2018-01-19 09:56
浏览 13

PHP MySQL不插入任何数据。 没有错误[重复]

This question already has an answer here:

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;
</div>
  • 写回答

2条回答 默认 最新

  • duanchi1230 2018-01-19 09:58
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动