Selecting the ID of a row you just inserted in the Database
Posted: Tue Apr 05, 2005 10:09 pm
First...I am using php 4x with a SQL Server DB.
I am trying to access the ID column of a row I just inserted into the database. I have done this in .NET before using @@Identity but can't figure out how to do it in PHP.
Basically for the row I insert into the DB I want to select that ID column so I can take that variable ($ID) and add it as a varible to display in the email I send out that has all the values I just inserted into the database.
See code below for what I am currently doing. Can anyone give me some code to accomplish this?
Phenom | Please use
I am trying to access the ID column of a row I just inserted into the database. I have done this in .NET before using @@Identity but can't figure out how to do it in PHP.
Basically for the row I insert into the DB I want to select that ID column so I can take that variable ($ID) and add it as a varible to display in the email I send out that has all the values I just inserted into the database.
See code below for what I am currently doing. Can anyone give me some code to accomplish this?
Code: Select all
global $link;
$host="";
$user="";
$password="";
$database = "";
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$title=$_POST['title'];
$company=$_POST['company'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$headline=$_POST['headline'];
$url=$_POST['url'];
$link = mssql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mssql_select_db($database,$link)
or die ("Couldn't select database");
$query = "INSERT INTO OutsideNewsRelease (FirstName,LastName,Title,Company,Phone,Email,Headline,URL,SubmissionDate) VALUES ('$first_name','$last_name','$title','$company','$phone','$email','$headline','$url','$SubmissionDate')";
mssql_query($query);
mssql_close();Code: Select all
tags when posting code.[/size][/color]