0

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!';
    }

?>

1 Answer 1

2

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Note that "unique" is set into a Apostrops, not in qutation Marks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.