For some reason when i submit a form data to the database, that that seems to get stored is the random ID

Ive attached the PHP code below that im using... can you see any issues with the code that might be stoping both email addreses, name and message not being store in the database

PHP Code:
// connect to database
$link mysql_connect ($host$user$password);
mysql_select_db ($dbname$link);

// creates a random number for the id, ans check to see if the random number currently exists in database
$success FALSE

$success == FALSE) { 
$rand rand(100000999999); 

$q "SELECT * FROM $tablename WHERE rand = '$rand'"
$r mysql_query($q$link);


mysql_num_rows($r)) { //id exists 
    } else { 
$success TRUE

// insert your data here with $rand as the id
$firstname mysql_real_escape_string($_POST['youremail']);
$lastname mysql_real_escape_string($_POST['name']);
$email mysql_real_escape_string($_POST['receiveremail']);
$datepicker mysql_real_escape_string($_POST['message']);

$query="INSERT INTO $tablename (rand, youremail, name, receiveremail, message) 
  VALUES ('"
.$rand."', '".$youremail."', '".$name."', '".$receiveremail."',   '".$message."')";
mysql_query($query) or die (mysql_error());