具有表结构的字段列表中的未知列#

时间:2016-01-30 19:45:12

标签: php mysqli sql-insert

所以我有一个问题,我已经谷歌了但是其他人有同样的问题是一个不同的答案。 每当我尝试从此PHP代码插入时,我都会收到错误:未知列'#字段列表中<$ strong>的值 。 我希望你能帮助我。感谢。

Structure de la table contas

CREATE TABLE IF NOT EXISTS `contas` (
  `cod_conta` int(11) NOT NULL AUTO_INCREMENT,
  `cod_char` int(9) NOT NULL,
  `username` varchar(180) NOT NULL,
  `password` varchar(180) NOT NULL,
  `email` varchar(180) NOT NULL,
  `datacc` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `adm` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`cod_conta`)
) ENGINE=InnoDB  DEFAULT CHARSET

And there is my code:

 <?php
    $link = mysqli_connect("localhost","root","","ftplayers_database") or die("Error " . mysqli_error($link));
    /* Convert POST in var */
        $username = $_POST['username'];
        $password = $_POST['password'];
        $email = $_POST['email'];
        $cod_char = $_POST['radio_char'];

    /* Encrypt password with md5 */
        $password = md5($password);

    /* Insert or return errors */
        $string = "SELECT * from `contas` WHERE username =`".$username."`";
        $sameusername = mysqli_query($link,$string) or die("Error:".mysqli_error($link));
        $howmanyusers = mysqli_num_rows($sameusername);

        if ($howmanyusers==0){
        $kfc=$username;
        $string ="INSERT INTO `contas`(`cod_char`,`username`,`password`,`email`) VALUES (".$cod_char.",`".$kfc."`,`".$password."`,`".$email."`)";
        echo $string;
        $insertuser = mysqli_query($link,$string) or die("Error:".mysqli_error($link));
        }

        mysqli_close($link);
    ?>

Just changed the '' from my query, now i get these:

  

Erreur desyntaxeprèsde   ''contas'('cod_char','username','password','email')VALUES   (2,'sdgsd','186672cc13'àlaligne 1

1 个答案:

答案 0 :(得分:1)

这是因为你之间写了$ username,我甚至不知道那个落后的东西叫什么而不是&#39; $ username&#39;。尝试使用引号。 还有其他变量:D

$string ="INSERT INTO `contas`(`cod_char`,`username`,`password`,`email`) VALUES (".$cod_char.",'".$kfc."','".$password."','".$email."')";