MySQL Insert Statement not working with GoDaddy Acct MySQL 5.0

If you are using MySQL 5.0 or greater on any host I’m sure then you may have encountered an situation where your insert statement does not update your database.

You probably logged into your phpMyAdmin and tested both the generated SQL and PHP insert, and nada. Well here is the reason why:

The SQL statement that is being generated does not have the database prefix. The database prefix is needed when you write your insert statement so that it can execute (at least it occurs this way in GoDaddy MySQL 5.0).

For example, you may be writing

<?php  $sql = "INERT INTO `table` (`columnOne`, `columnTwo`) VALUES ('Hi', '$phpVar');" mysql_query($sql); ?>

When you should actually be including the database name before the table name like this:

<?php  $sql = "INERT INTO `database`.`table` (`columnOne`, `columnTwo`) VALUES ('Hi', '$phpVar');" mysql_query($sql); ?>

Notice also how I use double quotes for my string instead of single quotes. I recommend that you do this so that if you are passing php variables to the SQL query, you don’t have to use the escape character (i.e. backslash). You can simply write your variable name and enclose it in single quotes.

If you have questions, post.

Oscar Valles



Filed under SQL

7 responses to “MySQL Insert Statement not working with GoDaddy Acct MySQL 5.0

  1. Dave

    v helpful on google search for GoDaddy headache.

  2. I have the same problem with a update statement

    looks like this $sqlUpdate = ‘UPDATE plProducts.allPens SET ‘.$collumn.’ = \”.$val.’\’ WHERE allPens.prodId = ‘.intval($id).’ LIMIT 1′;

    And even when i specify the database it still says “UPDATE command denied to user”

  3. I still have the same problem when doing a UPDATE statement.

    Here is how the sql statement looks like
    $sqlUpdate = ‘UPDATE plProducts.allPens SET ‘.$collumn.’ = \”.$val.’\’ WHERE allPens.prodId = ‘.intval($id).’ LIMIT 1′;

    Still get the a error : Query failed: UPDATE command denied to user……

    • I know syntax doesn’t usually play a role in user permission errors, but before you go any further, could you try using the following string? I slightly changed the syntax.

      Also, if the variables $val or $id are text, char or varchar in your table, please enclose them in single quotes.

      $sqlUpdate = “UPDATE plProducts.allPens SET $collumn = $val WHERE allPens.prodId = intval($id) LIMIT 1”;

  4. Teren

    Great!! and the tables’ name is case sensitive in godaddy MySQL:

    if there is a table called ‘Table’
    Insert into ‘Table’ …. (Correct)
    Insert into ‘table’ … (Error)

  5. @oscarvalles

    It still doesn’t work.

    Looks like a permission problem.

    All other mySql statements do work.

    Any suggestions?

Comment on this

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s