Neil Toulouse
Programmer
Hi there!
I am a PHP newbie so please bear with me
I have a client table containing ID (auto_increment), SURNAME and FIRSTNAME fields.
I can connect to the database and pass a query no problems. What I am trying to achieve is after inserting a record in to the table, I want to requery the table returning the last inserted record and then do two things.
Firstly, assign the SURNAME and FIRSTNAME to 2 variables and then display them.
Secondly, I want a third variable (say $newval) that is a concatenation of the first 4 letters of the surname, the first letter of the surname and then the ID padded out to 10 characters. This will then become CLIENTNO in the table.
For example:
ID = 1
SURNAME = Bloggs
FIRSTNAME = Joe
CONCATENATION = BLOGJ0000000001 (this bit I am really stuck on!!)
So, after connecting to the database I am doing the following:
$query = "INSERT INTO client (Surname, FirstName) VALUES ( 'Bloggs', 'Joe' )";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$lastid = mysql_insert_id();
(works fine)
$query = "Select * from client where ClientID = $lastid" ;
$result = mysql_query($sSQL) OR DIE ("Query Failed"
;
(not sure if this is working, but no error displayed)
...what do I do next? How do I assign the SURNAME and FIRSTNAME to variables, then display them and then the concatenation?
Presumably afterwards I would then do:
$query = "UPDATE client SET ClientNo = $newVal WHERE ID = $lastID";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
Any help much appreciated!
TIA
Neil
"I like work. It fascinates me. I can sit and look at it for hours..."
I am a PHP newbie so please bear with me

I have a client table containing ID (auto_increment), SURNAME and FIRSTNAME fields.
I can connect to the database and pass a query no problems. What I am trying to achieve is after inserting a record in to the table, I want to requery the table returning the last inserted record and then do two things.
Firstly, assign the SURNAME and FIRSTNAME to 2 variables and then display them.
Secondly, I want a third variable (say $newval) that is a concatenation of the first 4 letters of the surname, the first letter of the surname and then the ID padded out to 10 characters. This will then become CLIENTNO in the table.
For example:
ID = 1
SURNAME = Bloggs
FIRSTNAME = Joe
CONCATENATION = BLOGJ0000000001 (this bit I am really stuck on!!)
So, after connecting to the database I am doing the following:
$query = "INSERT INTO client (Surname, FirstName) VALUES ( 'Bloggs', 'Joe' )";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$lastid = mysql_insert_id();
(works fine)
$query = "Select * from client where ClientID = $lastid" ;
$result = mysql_query($sSQL) OR DIE ("Query Failed"

(not sure if this is working, but no error displayed)
...what do I do next? How do I assign the SURNAME and FIRSTNAME to variables, then display them and then the concatenation?
Presumably afterwards I would then do:
$query = "UPDATE client SET ClientNo = $newVal WHERE ID = $lastID";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
Any help much appreciated!
TIA
Neil
"I like work. It fascinates me. I can sit and look at it for hours..."