0

I confess, I am completely new to databases and PDO and not very experienced in php either, but I thought my code was pretty straightforward:

try {  
        $sql = "INSERT INTO fm_maps (user_id, map_name, map_width, map_height, tile_depth, min_zoom, max_zoom, rating)
        VALUES ($userid, $map_name, $width, $height, $tile_depth, $min_zoom, $max_zoom, '0')";                            //rating is still hardcoded as the field has no function yet
        // use exec() because no results are returned
        $this->conn->exec($sql);
        echo "New record created successfully";
      } catch(PDOException $e) {
        echo $sql . "<br>" . $e->getMessage();
      }

I'm trying to add some map metadata to the database table fm_maps. The connection to the db itself is successful, but when I try the above statement, I get the "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'MyMap' in 'field list'" error. Where 'MyMap' is the value of $map_name and thus the value that should go into the column map_name and not the name of the column itself. This code is pretty much a copy from a tutorial - what am I doing wrong? And how would I go about debugging this?

Note: user_id is a foreign_key, if that matters.

Merion
  • 195
  • 2
  • 10

0 Answers0