thefollower Posted September 12, 2008 Share Posted September 12, 2008 I keep getting an error on my script when i try to store the insert ID of the previous insert query... this is what I have (its for a registration script). <?php $query = "INSERT INTO `users` (Username,Password,Email,IP) Values ('$Username', '$Password', '$Email', '$ip')"; mysql_query($query) or die(mysql_error()); unset($_SESSION['security_code']); if (mysql_affected_rows() > 0) { // Send the email. $subject = "Welcome!"; $headers = 'From: Site Activation'; $message = "Thank you for registering!. To activate your account, please click on this link:<br><br>"; $message = $message. "/activate.php?x=" .mysql_insert_id. "&y=$EmailCode"; mail($Email, $subject, $message, $headers); } ?> The error i get is: Notice: Use of undefined constant mysql_insert_id - assumed 'mysql_insert_id' Not sure what i did wrong? Quote Link to comment https://forums.phpfreaks.com/topic/123949-solved-error-on-insert-id/ Share on other sites More sharing options...
Mchl Posted September 12, 2008 Share Posted September 12, 2008 mysql_insert_id() Quote Link to comment https://forums.phpfreaks.com/topic/123949-solved-error-on-insert-id/#findComment-639833 Share on other sites More sharing options...
The WebCoder Posted September 12, 2008 Share Posted September 12, 2008 Indeed, you have to replace mysql_insert_id with mysql_insert_id() , than your script will work. Quote Link to comment https://forums.phpfreaks.com/topic/123949-solved-error-on-insert-id/#findComment-639834 Share on other sites More sharing options...
thefollower Posted September 12, 2008 Author Share Posted September 12, 2008 Oh i see. thank you Quote Link to comment https://forums.phpfreaks.com/topic/123949-solved-error-on-insert-id/#findComment-639835 Share on other sites More sharing options...
Mchl Posted September 12, 2008 Share Posted September 12, 2008 Do you know why it's like that? Quote Link to comment https://forums.phpfreaks.com/topic/123949-solved-error-on-insert-id/#findComment-639837 Share on other sites More sharing options...
thefollower Posted September 12, 2008 Author Share Posted September 12, 2008 Not really =/ Quote Link to comment https://forums.phpfreaks.com/topic/123949-solved-error-on-insert-id/#findComment-639842 Share on other sites More sharing options...
Mchl Posted September 12, 2008 Share Posted September 12, 2008 mysql_insert_id() is a function. All functions have parentheses attached to their identifier. When you wrote just mysql_insert_id , the PHP parser didn't find parentheses, so it checked if there's a constant defined with a name mysql_insert_id (because that's how constants look like in PHP) Because no such constant was defined, PHP assumed that you wanted to use a string 'mysql_insert_id'. Some literature for you : Constants and how to define them Functions Quote Link to comment https://forums.phpfreaks.com/topic/123949-solved-error-on-insert-id/#findComment-639867 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.