insert data in mysql code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SeeMe
    New Member
    • Mar 2008
    • 18

    insert data in mysql code

    i want to ask, is it my coding got problem? Because when i run my program that can't be insert in mysql. cn some body let me noe my mistake?
    thanks[php]
    include("php_li brary/connect.php");
    $tablename = "jcy_users" ;
    $id = "603354";
    $username = "jcy";
    $password = "123";
    $userlever = "staff";
    $fullname = "jane";
    $datecreate = date(Y."-".m."-".d);
    $timecreate = date(H.":".i.": ".s);
    $query = "INSERT INTO ".$tablenam e." (id, username, password, userlever, fullname, datecreate, timecreate) VALUES ( '";
    $query .= $id."', '";
    $query .= $username."', '";
    $query .= $password."', '";
    $query .= $userlever."', '";
    $query .= $fullname."', '";
    $query .= $datecreate."', '";
    $query .= $timecreate."') ";
    echo $query."<br>";
    if (mysql_query($q uery))
    {
    echo "Sucess";
    }
    else
    {
    echo "Fail";
    }[/php]
    Last edited by ronverdonk; Apr 11 '08, 05:57 PM. Reason: warning: code tags!
  • rpnew
    New Member
    • Aug 2007
    • 189

    #2
    Originally posted by SeeMe
    i want to ask, is it my coding got problem? Because when i run my program that can't be insert in mysql. cn some body let me noe my mistake?
    thanks

    /*************** *************** *************** *************** *************** *************/
    include("php_li brary/connect.php");
    $tablename = "jcy_users" ;
    $id = "603354";
    $username = "jcy";
    $password = "123";
    $userlever = "staff";
    $fullname = "jane";
    $datecreate = date(Y."-".m."-".d);
    $timecreate = date(H.":".i.": ".s);

    $query = "INSERT INTO ".$tablenam e." (id, username, password, userlever, fullname, datecreate, timecreate) VALUES ( '";
    $query .= $id."', '";
    $query .= $username."', '";
    $query .= $password."', '";
    $query .= $userlever."', '";
    $query .= $fullname."', '";
    $query .= $datecreate."', '";
    $query .= $timecreate."') ";
    echo $query."<br>";
    if (mysql_query($q uery))
    {
    echo "Sucess";
    }
    else
    {
    echo "Fail";
    }
    /*************** *************** *************** *************** *************** **********/

    Hi,
    What is your page ECHOing like... is it echoing $QUERY perfectly??
    And what is the echo from if condition?

    Regards,
    RP

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      I dont understand why you're writing the code in that way... ?

      Just write it simple as:
      [php]
      INSERT INTO `tbl_name`
      (`col_1`, `col_2`)
      VALUES
      ('{$_var1}', '{$_var2}');
      [/php]

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        warning:

        Please enclose your posted code in [code] tags (See How to Ask a Question).

        This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

        Please use [code] tags in future.

        MODERATOR

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi.

          I, like rpnew, would like to see the query that is actually getting executed. The one that you print onto you page.
          Does the query look like you intended?

          Try using the mysql_error function if the query fails to see exactly what the problem is.
          And then tell us :)

          Comment

          • SeeMe
            New Member
            • Mar 2008
            • 18

            #6
            I slove my problem aldy. Thanks.

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by SeeMe
              I slove my problem aldy. Thanks.
              How did you solve it?

              Comment

              Working...