mysql_real_escape_string errror: expects string, resource given.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • roseple
    New Member
    • Jun 2009
    • 26

    mysql_real_escape_string errror: expects string, resource given.

    Hi, can anyone please help me why I got this error every I uploaded files.

    Error:
    Warning: mysql_real_esca pe_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwr oot\uploadingfi les\add_file.ph p on line 89

    Warning: mysql_real_esca pe_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwr oot\uploadingfi les\add_file.ph p on line 90

    Warning: mysql_real_esca pe_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwr oot\uploadingfi les\add_file.ph p on line 92
    Here is the code on the said warning message:
    Code:
    # Gather all required data
            $name = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['name']);
            $mime = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['type']);
            $size = $_FILES['uploaded_file']['size'];
            $data = mysql_real_escape_string($dbLink, file_get_contents($_FILES['uploaded_file']['tmp_name']));
    And because of that error the name and mime of the files I uploaded didn't appear, thats why I cannot properly download the files. Maybe because the mime/filetype is not present.

    Your help will be highly appreciated.

    Thanks guys..
    Last edited by Atli; Jun 19 '09, 08:20 AM. Reason: Moved from the article into it's own thread.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Originally posted by roseple
    Hi, can anyone please help me why I got this error every I uploaded files.
    Hi.

    Did you swap back to the old mysql extension, or did you just forget the "i" in the function name?

    The old mysql_real_esca pe_string function expects the first parameter to be a string and the second one to be the mysql connection resource.
    Your code has it backwards.

    The improved mysqli_real_escaped_s tring function (note the "i" in the function name) expects the first parameter to be a mysqli object, and the second one to be a string.
    Your code has the parameters right, but leaves out the "i" in the function name.

    Comment

    • roseple
      New Member
      • Jun 2009
      • 26

      #3
      Hi, I'm sorry I have another question..
      Can anyone know why this warning message occur:
      Warning: mysql_real_esca pe_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwr oot\uploadingfi les\add_file.ph p on line 89

      Warning: mysql_real_esca pe_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwr oot\uploadingfi les\add_file.ph p on line 90

      Warning: mysql_real_esca pe_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwr oot\uploadingfi les\add_file.ph p on line 92
      Here's the code on the said line.
      Code:
      $name = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['name']);
              $mime = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['type']);
              $size = $_FILES['uploaded_file']['size'];
              $data = mysql_real_escape_string($dbLink, file_get_contents($_FILES['uploaded_file']['tmp_name']));
      And because of that warning messae the name, mime and filedata is not present that's why I cannot properly download the files I uploaded.

      Thank you very much in advance.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by roseple
        Can anyone know why this warning message occur:
        because you defined the parameters in the wrong order. as stated in the manual, the string comes first and the resource comes second.

        Comment

        • roseple
          New Member
          • Jun 2009
          • 26

          #5
          Can you tell me how can I do that..

          Thanks

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            Originally posted by roseple
            Can you tell me how can I do that..
            do what? you mean to correct the error?

            Comment

            • roseple
              New Member
              • Jun 2009
              • 26

              #7
              Yup, if you don't mind..

              Thank you very much..

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                You have the parameters of the function in reverse order.
                One would think the solution would be obvious...

                The database link is supposed to go after the data.
                (Or not at all. That would work to.)

                Keep in mind that the example code in my article is meant for a different function, as I explained in my first post in this thread.

                Take a look at the examples in the links both myself and Dormilich posted. See how the parameters are used there.

                Comment

                Working...