Search code examples
phpmysqlgoto

goto is not working in php giving syntax error, unexpected ':' on line number 10


Below is the code i am using

Again:
  $rand = mt_rand(100000,999999);
  $sql = "select * from replogins where access_code = $rand";
      $res = mysql_query($sql); 
  if(mysql_num_rows($res))
goto Again;

please help


Solution

  • You could easily replace the goto with a while loop, solving your problem AND getting rid of that goto at the same time. ;)

    do {
        $rand = mt_rand(100000,999999);
        $sql = "select * from replogins where access_code = $rand";
        $res = mysql_query($sql); 
    } while(mysql_num_rows($res));