Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/123949-solved-error-on-insert-id/
Share on other sites

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.