title: Select into @var always null
body: <p>Alright so here is my mysql function</p>
  
  <pre><code>DELIMITER $$
  
  CREATE DEFINER=`root`@`%` FUNCTION `password_reset_request`(spUsername VARCHAR(120)) RETURNS varchar(255) CHARSET utf8
  BEGIN
      DECLARE vcode VARCHAR(255);
      DECLARE muid INTEGER;
      SET vcode = "test";
  
      select id into muid from scheme.users where username=@spUsername limit 1;
  
      RETURN muid;
  
      IF muid is null THEN
          RETURN 'BADUSER';
      ELSE
          insert into `password_reset`(`uid`,`code`) 
              values ( muid,vcode)
          ON DUPLICATE KEY UPDATE
              `code`=vcode;
          RETURN vcode;
      END IF;
  END
  </code></pre>
  
  <p>Problem I have is that <code>muid</code> is always <code>null</code>. I've even replaced all <code>muid</code> with <code>@muid</code>, which didn't change the outcome. </p>
  
  <p>When I run <code>select id from scheme.users where username=@spUsername limit 1;</code> and replace <code>@spUsername</code> with the same value I'm passing into the function, it gives me the right info.</p>
  
  <p>I've also put in <code>RETURN @spUsername</code> to verify that that variable is set correctly, and it is.</p>
  
  <p>Any ideas? Probably doing something dumb.</p>
  
  <p>Table Schemes</p>
  
  <pre><code>CREATE TABLE `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `username` varchar(120) NOT NULL,
    `email` varchar(200) NOT NULL,
    `password` varchar(200) NOT NULL,
    `vcode` varchar(120) NOT NULL,
    `isverified` bit(1) DEFAULT b'0',
    `verifydate` datetime DEFAULT NULL,
    `date_created` datetime DEFAULT NULL,
    `date_modified` datetime DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `username_UNIQUE` (`username`)
  )
  
  CREATE TABLE `password_reset` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `uid` int(11) NOT NULL,
    `code` varchar(255) NOT NULL,
    `iscompleted` bit(1) DEFAULT b'0',
    `date_created` datetime DEFAULT NULL,
    `date_modified` datetime DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uid_UNIQUE` (`uid`)
  )
  </code></pre>