Mysql error:Duplicate entry '.' for key 'PRIMARY'

Discussion in 'Web Server' started by Saptarshi Nag, Jun 16, 2014.

  1. Saptarshi Nag

    Saptarshi Nag Member

    Messages:
    42
    Likes Received:
    28
    Trophy Points:
    18
    I have written a php script and the following mysql error is coming
    Duplicate entry '.' for key 'PRIMARY'
    The code is as follows---
    $name=$_POST["name"];
    $eid=$_POST["id"];
    $year=$_POST["year"];
    $dept=$_POST["department"];
    $un=$_POST["username"];
    $pass=$_POST["password"];
    $regdata="INSERT INTO user_table(Fullname,Email,Year,Dept,Username,Password) VALUES('.$name.','.$eid.','.$year.','.$dept.','.$un.','.$pass.')";
    mysql_connect("localhost","root","password") or die(mysql_error());
    mysql_query("CREATE DATABASE IF NOT EXISTS user_db") or die(mysql_error());
    mysql_select_db("user_db") or die(mysql_error());
    mysql_query("CREATE TABLE IF NOT EXISTS user_table(
    Fullname CHAR,
    Email CHAR
    Year CHAR,
    Dept CHAR,
    Username CHAR,
    Password CHAR,
    PRIMARY KEY(Username)") or die(mysql_error());
    mysql_query($regdata) or die(mysql_error());
    mysql_close();

    Last edited: Jun 16, 2014
  2. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    1,274
    Likes Received:
    431
    Trophy Points:
    83
    hmm. should
    Code:
    PRIMARY KEY(Username)") or die(mysql_error());
    be
    Code:
    PRIMARY KEY("(Username)") or die(mysql_error());
  3. Saptarshi Nag

    Saptarshi Nag Member

    Messages:
    42
    Likes Received:
    28
    Trophy Points:
    18
    No there's no problem with that.the closing double quote has the starting one in "CREATE TABLE...

Share This Page