MySQL said 1064 你的 SQL 语法有误
MySQL said 1064 You have an error in your SQL syntax
我为我的用户注册页面写了一个 MYSQL 过程,我已经写了 PHP 部分从那里发送数据到 MySQL,它工作正常(试过虚拟数据和检索)。但是我猜我的处理程序或交易存在某种问题
这是我的程序:
BEGIN
DECLARE unamec INT;
DECLARE emailc INT;
DECLARE m INT;
DECLARE msg VARCHAR(100);
DECLARE EXIT HANDLER FOR SQLEXCEPTION SET m=1;
START TRANSACTION;
SET autocommit=0;
SELECT COUNT(*) INTO unamec FROM login WHERE uname=`@user`;
IF unamec=0 THEN
SELECT COUNT(*) INTO emailc FROM login WHERE email=@email;
IF emailc=0 THEN
INSERT INTO login (uname, hash, email, role) values(@user,MD5(@password),@email,'1');
SET msg='Successfully Registered';
ELSE
SET msg='Email Already Exists';
END IF;
ELSE
SET msg='Username Already Exists';
END IF;
COMMIT;
END;
END;
IF m=1 THEN
ROLLBACK;
SET msg='ERROR';
END IF;
SELECT msg as message;
END
我总是得到错误
MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'END;
IF m=1 THEN
ROLLBACK;
SET msg='ERROR';
END IF;
SELECT msg as message;' at line 23
有什么明显的我遗漏的吗?我已经尝试了一段时间来解决这个问题,几乎所有结果都显示相同的错误。
任何帮助将不胜感激。
好的,我编辑了自己的代码并得到了所需的结果。
我所做的更改是:
BEGIN
DECLARE unamec INT;
DECLARE emailc INT;
DECLARE m INT;
DECLARE msg VARCHAR(100);
DECLARE EXIT HANDLER FOR SQLEXCEPTION
START TRANSACTION;
SET autocommit=0;
SELECT COUNT(*) INTO unamec FROM login WHERE uname=`@user`;
IF unamec=0 THEN
SELECT COUNT(*) INTO emailc FROM login WHERE email=@email;
IF emailc=0 THEN
INSERT INTO login (uname, hash, email, role) values(@user,MD5(@password),@email,'1');
SET msg='Successfully Registered';
ELSE
SET msg='Email Already Exists';
END IF;
ELSE
SET msg='Username Already Exists';
END IF;
COMMIT;
BEGIN
ROLLBACK;
SET msg='ERROR';
END;
SELECT msg as message;
END
如果有人得到任何其他答案,仍然不胜感激。
无论如何,上面的代码现在可以正常工作了。
我为我的用户注册页面写了一个 MYSQL 过程,我已经写了 PHP 部分从那里发送数据到 MySQL,它工作正常(试过虚拟数据和检索)。但是我猜我的处理程序或交易存在某种问题
这是我的程序:
BEGIN
DECLARE unamec INT;
DECLARE emailc INT;
DECLARE m INT;
DECLARE msg VARCHAR(100);
DECLARE EXIT HANDLER FOR SQLEXCEPTION SET m=1;
START TRANSACTION;
SET autocommit=0;
SELECT COUNT(*) INTO unamec FROM login WHERE uname=`@user`;
IF unamec=0 THEN
SELECT COUNT(*) INTO emailc FROM login WHERE email=@email;
IF emailc=0 THEN
INSERT INTO login (uname, hash, email, role) values(@user,MD5(@password),@email,'1');
SET msg='Successfully Registered';
ELSE
SET msg='Email Already Exists';
END IF;
ELSE
SET msg='Username Already Exists';
END IF;
COMMIT;
END;
END;
IF m=1 THEN
ROLLBACK;
SET msg='ERROR';
END IF;
SELECT msg as message;
END
我总是得到错误
MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'END;
IF m=1 THEN
ROLLBACK;
SET msg='ERROR';
END IF;
SELECT msg as message;' at line 23
有什么明显的我遗漏的吗?我已经尝试了一段时间来解决这个问题,几乎所有结果都显示相同的错误。
任何帮助将不胜感激。
好的,我编辑了自己的代码并得到了所需的结果。
我所做的更改是:
BEGIN
DECLARE unamec INT;
DECLARE emailc INT;
DECLARE m INT;
DECLARE msg VARCHAR(100);
DECLARE EXIT HANDLER FOR SQLEXCEPTION
START TRANSACTION;
SET autocommit=0;
SELECT COUNT(*) INTO unamec FROM login WHERE uname=`@user`;
IF unamec=0 THEN
SELECT COUNT(*) INTO emailc FROM login WHERE email=@email;
IF emailc=0 THEN
INSERT INTO login (uname, hash, email, role) values(@user,MD5(@password),@email,'1');
SET msg='Successfully Registered';
ELSE
SET msg='Email Already Exists';
END IF;
ELSE
SET msg='Username Already Exists';
END IF;
COMMIT;
BEGIN
ROLLBACK;
SET msg='ERROR';
END;
SELECT msg as message;
END
如果有人得到任何其他答案,仍然不胜感激。
无论如何,上面的代码现在可以正常工作了。