Forum Moderators: coopster
Once a card has been submitted php generates an id
$db_id = uniqid(rand (),false);
and creates a new record for the e-card in my database
Within the same loop it sends an email to the recipient notifying them of the e-card and it's location - fun/ecard.php?id=
Ofcourse if I write the location as id=$db_id I get a brand new ID instead of the ID for the record that was just created.
So I'm wondering if I can return the value of the ID field for the record that's just been inserted?
Whilest card_id is the primary key it does not auto increment so mysql_insert_id() isn't useful, or so I understand?
Whilest card_id is the primary key it does not auto increment
Why not? I don't see the point in bending over backwards to do something that's already built-in. Ok, sorry...ramble over.
$db_id should remain the same until you run the unique command again. Is this done in a loop? Maybe you need to move something up in the script.
I don't have it auto incrementing as the id's are generated at random, the reason I'm doing this is to retain some level of privacy for the cards that have been created
If auto incrementing would be easy to browse through id=1 id=2 and so on.
if ($sendcard){$db_id = uniqid(false);
$sql2 = "INSERT INTO ecard (card_id, card_ref, sender_ad, sender_nm, recip_ad, recip_nm, card_msg) VALUES ('$db_id', '$card_ref', '$db_senderad', '$db_sendernm', '$db_recipad', '$db_recipnm', '$db_msg')";
$result2 = mysql_query($sql2);
if (!$result2) {
$message = "Failed to create Ecard.". mysql_error();
} else {
$message = "Your Ecard has been sent! You can see it here http://www.example.net/fun/ecard.php?id=THE_SAME_ID_AS_THE_RECORD_INSERTED"
}; [edited by: jatar_k at 1:51 pm (utc) on April 1, 2007]
[edit reason] please use example.net [/edit]