Problem with insert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zek2005

    #1

    Problem with insert

    I have a problem with an insert. The connection to DB works fine and I
    receive an OK when the PHP process but nothing is inserted in the DB.
    I added an echo of mysql_affected_ rows and the result is -1. That's
    why I get an OK?

    $query="INSERT INTO preguntas (pregunta, id_usuario, fecha) VALUES
    ('$pregunta','$ id',current_dat e)";
    $result=mysql_d b_query($databa se,$query,$link );
    if(mysql_affect ed_rows($link))
    {
    echo "OK";
    }
    else
    {
    echo "Nothing inserted";
    }

    Thanks for your help

    Ezequiel

  • Jerry Stuckle

    #2
    Re: Problem with insert

    zek2005 wrote:
    I have a problem with an insert. The connection to DB works fine and I
    receive an OK when the PHP process but nothing is inserted in the DB.
    I added an echo of mysql_affected_ rows and the result is -1. That's
    why I get an OK?
    >
    $query="INSERT INTO preguntas (pregunta, id_usuario, fecha) VALUES
    ('$pregunta','$ id',current_dat e)";
    $result=mysql_d b_query($databa se,$query,$link );
    if(mysql_affect ed_rows($link))
    {
    echo "OK";
    }
    else
    {
    echo "Nothing inserted";
    }
    >
    Thanks for your help
    >
    Ezequiel
    >
    First of all, mysql_db_query was deprecated in PHP Version 4.0.5 and
    should not be used. See the doc for more info.

    And, just like in your previous question, you aren't checking the result
    of the query. Did it work or not? You'll either get a resource back or
    FALSE. In the former case it worked. In the latter case it didn't.

    ALWAYS check the result of a MySQL call. If it fails, use mysql_error()
    to display the error message.


    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • =?iso-8859-1?q?Joachim_M=E6land?=

      #3
      Re: Problem with insert

      On Sun, 11 Feb 2007 05:53:51 -0800, zek2005 wrote:
      $result=mysql_d b_query($databa se,$query,$link );
      From the manual:
      This function is deprecated, do not use this function. Use
      mysql_select_db () and mysql_query() instead.



      Or, if you insist on using a deprecated function, please check for
      warnings: "If by chance no connection is found or established, an
      E_WARNING level warning is generated." My guess is a username/password
      mismatch...

      --
      Regards/mvh Joachim Mæland

      If everything seems under control, you're just not going fast enough.
      -Mario Andretti.

      Comment

      Working...