Hi,
I'm setting up an invitational email for a project I'm working on. I have some forms that input a bunch of emails with a standard message. Then a function is called that creates a random key. They need this key to register. After the key is generated, before it's passed a value back to the caller, it attempts to INSERT INTO the key into a db row. Then when the user creates their account they input the information into the row that matches their key. That's the plan, but I now I can't get my insert into function to run properly. I've done a lot of google searching trying to resolve the error with no luck. Thank you for the help. I'm relying on a bad PHP tutorial book, tiny experience and the helpful commenters of this forum for help on this project.
Here is the code:
<?php
function create_activation_code(){
// CREATE AC
$set1 = rand(1000,100000);
$set2 = rand(10,450);
$set3 = rand(1000,100000);
$activation_code = "$set1".'a'."$set2".'b'."$set3";
// SEND IT TO THE SERVER TO BE PLACEHELD
$my_id = 'my_name';
$my_pass = 'my_pass';
$my_db = 'my_db';
$connect = mysql_connect('localhost', $my_id, $my_pass);
$select = mysql_select_db($my_db, $connect);
$query = "INSERT INTO my_db (private_id) VALUE ('$activation_code')";
if($select = mysql_query($query)){
print('db entry successful');
}
else{
print('error');
$error = mysql_error();
echo $error;
}
mysql_close();
// OUTPUT TO FUNCTION CALL
return $activation_code;
} ?>
This generates error:
errorDuplicate entry '' for key 2
If I change:
$query = "INSERT INTO mf_login_info (private_id) VALUE ('$activation_code')";
to
$query = "INSERT INTO mf_login_info (private_id) VALUE ($activation_code)";
I get:
errorUnknown column 'the key generated above' in 'field list'
It must be a syntax error. Thanks.