Re: INSERT problem with MySQL/PHP

From: Date: Tue, 19 Jun 2001 00:55:18 +0000
Subject: Re: INSERT problem with MySQL/PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-54305@lists.php.net to get a copy of this message
Todd, Did you echo $sql and examine it? Did you try the statement at the mysql console? Does the list of values exactly match the field list? Did you try the alternate syntax .... INSERT [LOW_PRIORITY | DELAYED] [IGNORE] [INTO] tbl_name SET col_name=expression, col_name=expression, ... as in the MySQL docs? I'm really curious about what $sql looks like when you echo it. I've been surprised more than once. Miles Thompson At 04:11 PM 6/18/01 -0700, Todd A. Jacobs wrote:
PHP: 4.0.4pl1 MySQL: 3.23.36-1 I have the following code fragment, which uses the same connection parameters elsewhere to *successfully* to retrieve data from a database, so this doesn't appear to be a permissions problem with MySQL. However, nothing happens with inserts; no rows are added at all. All I get is a message form mysql_error() saying "Query was empty." Can anyone tell me what might be wrong?
    $user_idx  = 1;
    $objective = 1;
    $question  = 'Foo';
    $question_type = 'singular';
    $connection_id = mysql_connect ('192.168.1.1', 'php', 'password')
        or die ("No connection.\n");
    $sql = "INSERT INTO question VALUES (NULL, $user_idx, $objective,
        '$question', '$question_type', NULL, NULL)";
    $result = mysql_db_query('item_db', $sql_query, $connection_id);
    echo "<pre>";
    echo "\nDebugging output:\n";
    echo "\tSQL: $sql\n";
    echo "\tError: ", mysql_error(), "\n";
    echo "\tLast insert ID: ", mysql_insert_id(), "\n";
    echo "\tResult: $result\n";
    echo "</pre>\n";
-- Todd A. Jacobs CodeGnome Consulting, LTD


« previous php.general (#54305) next »