sql query with php problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjay123456
    New Member
    • Sep 2006
    • 125

    sql query with php problem

    Dear friends ,

    How i write this query in mysql

    data r following
    $que=$_POST['que'];

    $quiz=$_POST['quiz'];

    its variable inserted in to mysql is following query correct or not

    mysql_query("IN SERT INTO result(que,ans)
    VALUES ($que,$quiz)");

    sanjay
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Yes, but when the fields have data type character, you better store the values between single quotes, like this
    Code:
    mysql_query("INSERT INTO result(que,ans) 
    VALUES ('$que', '$quiz')");
    Ronald :cool:

    Comment

    • sanjay123456
      New Member
      • Sep 2006
      • 125

      #3
      Sir ,

      thx ur quick reply sir
      plz tell me that both que and quiz are as a interger and both r coming integer
      and in mysql table i aslo declare int can i convert both in int or they r in int in php page

      because in jsp everything in form of string

      sanjay

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        When both $que and $quiz are integers your original INSERT statement is correct. I.e.
        Code:
        mysql_query("INSERT INTO result(que,ans) 
        VALUES ($que,$quiz)");
        Ronald :cool:

        Comment

        • satya61229
          New Member
          • Feb 2007
          • 24

          #5
          and you should quote the any input by user, for security reason.
          check for get_magic_quote s_gpc() and mysql_real_esca pe_string();

          Comment

          Working...