Gururaju Hiddenx
Gururaju Hiddenx

Reputation: 199

Storing rand() output to mysql database ERROR

I wanted to store the output of rand() function into my database, I have been getting the error!

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 'unique) VALUES('964350')' at line 1

This is my code

<?php

require_once('connect.php');

    $unique = rand(100000, 999999);

    $uni = "INSERT INTO registrations (unique) VALUES('$unique')";
    $result = @mysql_query($uni);

        if($result) {
            $sucmsg_arr[] = 'Registration Successful!';
    }

?>

Upvotes: 0

Views: 68

Answers (1)

SOehl
SOehl

Reputation: 417

'unique' is a keyword like 'select' or 'delete'.

Try it with INSERT INTO registrations (`unique`) VALUES('$unique')

Upvotes: 2

Related Questions