php error重复输入' 0'对于第1行的密钥1
include ("connect.php");
include ("register.php");
$urlIdd = isset($_POST['$urlId']);
$urlnamee = isset($_POST['$urlname']);
$dateofurll = isset($_POST['$dateofurl']);
$createe = mysql_query ("CREATE TABLE 'urls'
( 'urlId' INT(4) NOT NULL PRIMARY KEY AUTO INCREMENT NOT NULL,
'urlname' VARCHAR(50) NOT NULL,
'dateofurl' DATETIME NOT NULL"
);
$insertt=mysql_query("INSERT INTO urls (urlId, urlname, dateofurl)
VALUES ('$urlId', '$urlname', '$dateofurl')");
if(!$insertt){
echo mysql_error();
} else
echo "a row has been created successfully";
$updatee = mysql_query("UPDATE urls SET(urlId, urlname, dateofurl)
VALUES ('$urlId', '$urlname', '$dateofurl')");
if(!$updatee){
echo mysql_error();
} else
echo "a row has been changed successfully";
$deletee = mysql_query("DELETE FROM urls
SET(urlId, urlname, dateofurl)
VALUES ('$urlId', '$urlname', '$dateofurl')");
答案 0 :(得分:1)
这是mysql错误,而不是PHP,这意味着您正在尝试为PRIMARY KEY列添加重复值
我可以在你的代码中看到这一行
$createe = mysql_query ("CREATE TABLE IF NOT EXISTS 'urls'
( 'urlId' INT(4) NOT NULL PRIMARY KEY AUTO INCREMENT NOT NULL,
'urlname' VARCHAR(50) NOT NULL,
'dateofurl' DATETIME NOT NULL"
);
注意:使用CREATE TABLE IF NOT EXISTS
因为您的脚本更有可能被执行多次,如果已经创建了TABLE,您的脚本不会产生任何错误
您的urlId
是您的PRIMARY KEY
并且是AUTO_INCREMENT
,这意味着在插入数据时,您无需输入其值,插入新行时它会自动递增。
我的建议是从您的查询中移除urlid并将其设为这样,通过执行此操作,urlid
的值将自动插入
$insertt=mysql_query("INSERT INTO urls ( urlname, dateofurl)
VALUES ( '$urlname', '$dateofurl')");
答案 1 :(得分:-1)
你试过不指定你的urlID吗?它有一个自动增量..
查询shud就像这样
$insertt=mysql_query("INSERT INTO `urls` (`urlname`, `dateofurl`) VALUES ('$urlname', '$dateofurl')");
$updatee=mysql_query("UPDATE `urls` SET `urlname`='$urlname' , `dateofurl`='$dateofurl' WHERE `urlId`=$urlId");
$deletee= mysql_query("DELETE from `urls` WHERE `urlId`=$urlId");