|
-
Mar 3rd, 2004, 02:18 PM
#1
Thread Starter
Frenzied Member
Insert into identifier field
I'm doing the following:
PHP Code:
$query1 = "INSERT [" . $ctype . "] DEFAULT VALUES";
$result1 = mysql_query($query1);
$query1 = "SELECT MAX(ID) FROM '" . $ctype . "'";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_array($result1);
echo "<p class=chatter>ID : " . $row1[0] . "<br>";
And I'm getting an error on the fetch_array line. This works perfectly in MS SQL Server, but I'm trying to do with with MySQL for another project. I guess the question is, am I doing the initial insert correctly?
The idea is to insert the ID field and then update the rest of the fields where ID = "newly inserted ID"
-
Mar 3rd, 2004, 04:02 PM
#2
Stuck in the 80s
What is the error you are getting? And it's always good to do:
PHP Code:
$result1 = mysql_query($query1) or die(mysql_error());
$row1 = mysql_fetch_array($result1) or die(mysql_error());
As that can give better and more specific errors.
-
Mar 4th, 2004, 04:24 PM
#3
Frenzied Member
if you did an insert then you can use
mysql_insert_id() to get the last ID made.
mysql_insert_id() returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query using the given link_identifier. If link_identifier isn't specified, the last opened link is assumed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|