www.webdeveloper.com
Results 1 to 12 of 12

Thread: mysql_errno Stops form :(

  1. #1
    Join Date
    Mar 2006
    Posts
    38

    mysql_errno Stops form :(

    I purchased a website that has a small program where users enter data to a database.

    None of the files have been edited.

    I transferred the files to a different server today, created the new database (with the same names/password) and imported the tables.

    Now when I enter a form like I did on the previous server I get this error "Problem adding to database"

    That is the message that happens when filling out the form fails.

    PHP Code:
        if (mysql_errno() != 0) {
            echo 
    "Problem adding to database";
            echo 
    "\nsql=$sql\n";
            echo 
    mysql_error();
        } 
    I'm confused why this would happen.
    Last edited by Clint Malarchuk; 03-14-2011 at 12:46 PM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    Do you get any of the other debug info after that message (the stuff that would be output by the following echo of $sql and then mysql_error())?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2006
    Posts
    38
    Quote Originally Posted by NogDog View Post
    Do you get any of the other debug info after that message (the stuff that would be output by the following echo of $sql and then mysql_error())?
    Yes

    The form is actually really big (but like it said it worked perfectly on the other server).

    When I hit 'send' instead of the form success page I get an error like this...

    Problem adding to database sql=insert into mydatabasename.database (

    and after that is the full list of each field and the values

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    What is the very last part of the error output, i.e. the result of the mysql_error() call? That should tell you what part of the query MySQL did not like.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Mar 2006
    Posts
    38
    Because of confidnetiality reasons I can't pubicize the form details but there are a few things that are coming up that I think you're looking for is

    on duplicate key
    Incorrect integer value

    But like I said on the only server the forms still work perfectly.

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    Probably a PHP version issue. See http://bugs.mysql.com/bug.php?id=18551.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Mar 2006
    Posts
    38
    Thanks, I found out that both servers use the same version of PHP

  8. #8
    Join Date
    Mar 2006
    Posts
    38
    I have discovered that one server uses Windows and the other (working) server uses Linux. Does that mean anything?

  9. #9
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    I suppose it's possible, though it would seem unlikely. I'd be more suspicious that one MySQL installation is configured to run in MySQL 4 compatibility mode while the other is not (see the "bug" report link in my previous reply). You can try adding the following to your script after the mysql connection is made but before the query is executed, in order to make it run in MySQL 4 mode, too:
    PHP Code:
    mysql_query("set sql_mode = ''"); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  10. #10
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    PS: Or you could just try to fix the query.

    If the issue is the same as described in that "bug" report, it could be a case where you are trying to assign an empty string to an integer field, in which case you should use the keyword NULL instead of empty quotes for that value (or else a zero if that's what you really want).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  11. #11
    Join Date
    Mar 2006
    Posts
    38
    PHP Code:
    mysql_query("set sql_mode = ''"); 
    worked, thanks.

  12. #12
    Join Date
    Mar 2006
    Posts
    38
    It looks like I jumped the gun.

    The code you gave me allowed the me to get past any errors but it didn't actually add anything to the database

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles