Using NSURLRequest to pass key-value pairs to PHP script with POST

后端 未结 6 2086
灰色年华
灰色年华 2021-01-31 20:51

I\'m fairly new to objective-c, and am looking to pass a number of key-value pairs to a PHP script using POST. I\'m using the following code but the data just doesn\'t seem to b

6条回答
  •  故里飘歌
    2021-01-31 21:23

    Edit: Has been fixed in OP.


    This may not be your sole problem (I don't know my way around objective-c), but here goes:

    mysql_query("INSERT INTO php_test (SENDER, RCPT, MESSAGE) 
    VALUES ($sender, $rcpt, $message)");
    

    You're not quote-enclosing your strings - MySQL is bound to have a hissy fit over that.

    mysql_query("INSERT INTO php_test (SENDER, RCPT, MESSAGE) 
    VALUES ('$sender', '$rcpt', '$message')");
    

    Beyond that, generally, even if your script is not reachable from the outside, you shouldn't trust user input and either use mysql_real_escape_string() to escape your values before you insert them into the SQL statement to prevent SQL injection, or use prepared statements (preferred) - otherwise single quotes in your legitimate data will break the SQL statement's syntax.

    Entirely ungraceful example for reference:

    mysql_query("INSERT INTO php_test (SENDER, RCPT, MESSAGE) 
    VALUES ('" . mysql_real_escape_string($sender) ."',"
    ." '" . mysql_real_escape_string($rcpt) ."',"
    ." '" . mysql_real_escape_string($message) ."')");
    

提交回复
热议问题