Son of CREATE TABLE -- INSERT INTO!

Hi all,
Thanks for the CREATE TABLE help now the next problem.

The query below always dies. $newtab contains the name of the table which has been created. I tried the formats given as solution for the previous problem (double quotes or single quotes with string concatenation) but neither works. Advice needed.

Mike

      $query = "INSERT INTO $newtab
                    (booknumber)
                  VALUES
                    ($booknumber)";
      $result = mysql_query($query)
            or die('nothing doing');

Exactly, $booknumber is empty.
So, now all you have to do is understand why it is empty, and fix it :slight_smile:

you got it, that’s exactly what it implies

Thanks Guido, that certainly gives useful information and it tells me:

mysql error Column count doesn’t match value count at row 1 in query INSERT INTO Fotografie (booknumber) VALUES ()

while the query seems ok:
$newtab content is ok and valid as is $booknumber as far as I can see. Is this part of the error message - VALUES () - telling me that the $booknumber is empty or something?

Thanks.


     $query = "INSERT INTO $newtab
                    (booknumber)
                  VALUES
                    ($booknumber)";
      $result = mysql_query($query)
            or die('mysql error ' . mysql_error() . ' in query ' . $query);

You cannot create table in such way. You should

CREATE TABLE $tbl …
INSERT INTO $tbl VALUES(…

Don’t use such a generic error message, use something more meaningful, like:


$result = mysql_query($query)

            or die('mysql error ' . mysql_error() . ' in query ' . $query);