我为我的用户注册页面写了一个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
有什么东西显而易见我错过了吗?我已经尝试了一段时间来解决这个问题,几乎所有的结果都显示出同样的错误。
任何帮助都将受到高度赞赏。
答案 0 :(得分:1)
好的,我编辑了自己的代码并获得了所需的结果。
我所做的改变是:
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
如果有人得到任何其他答案,仍然会感激。
无论如何,上面的代码现在工作正常。