MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Gary W. Smith Date:February 25 2009 10:10pm
Subject:RE: non-auto increment question
View as plain text  
Not sure that this is the problem BUT you should probably qualify the name of the variable
such that "SELECT MAX(id) AS id FROM book". But you don't want "max(id) as id" but rather
"max(id) + 1 as id".  With that you can then just return the final value.  Also, if you
don't want to alias the value (or whatever it's called) you should use $row[0] to get it
by ordinal posistion.
As for now wanting to use autoincrement, you can run into a race condition where two
people are inserting at the same time, thus having the same generated id.
Hope that helps.


From: PJ [mailto:af.gourmet@stripped]
Sent: Wed 2/25/2009 2:01 PM
To: MySql; php-general@stripped
Subject: non-auto increment question

I want to insert a new table entry 1 number higher than the highest in
the field (id). I cannot use auto-increment.
And I want to show the value of the field to be added in an input field
on the web page:
if (isset($_REQUEST["AddNewBooksRequest"])) {
    $SQL = "SELECT MAX(id) FROM book";
        $result = mysql_query($sql, $db);
        $bookCount = mysql_num_rows($result);
            for ($i=0; $i < $bookCount; $i++) {
            $row = mysql_fetch_array($result);
            $idIN    = $row["id"]+1;
    $idIN            = $_POST["idIN"];
    $titleIN        = $_POST["titleIN"];


<td colspan="2">
echo "<input type='text' name='titleIN' value='$idIN' disabled size='2'>";

What am I doing wrong? (The query works and returns the right nr. but
what do I have to do to add 1 to that number and then display it in the
on page and post it to the table?


Phil Jourdan --- pj@stripped <> <> 

MySQL General Mailing List
For list archives:
To unsubscribe:

non-auto increment questionPJ25 Feb
  • RE: non-auto increment questionGary W. Smith25 Feb