Really really EASY php/mysql - 1 line of code needed!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • who
    So Fucking Banned
    • Aug 2003
    • 19593

    #1

    Really really EASY php/mysql - 1 line of code needed!

    hi I just need someone to help me with one line of code in wordpress backend.

    I have a new field in the 'wp_user' table of the wordpress database,

    All I need to do is write some one line of code which will update that field with a value from $_POST

    I am struggling now with this crap for a couple of hours... I feel like a retard and most likely am. But can anyone help me out?

    Thanks.
  • Pryda
    Confirmed User
    • Dec 2005
    • 906

    #2
    mysql_query("UPDATE [yourtablename] SET wp_user = '".mysql_real_escape_string(trim($_POST['username']))."'");

    That will do the trick. It will fill every wp_user in the table with your POST value. If that is not what you want, you will have to specify a condition using WHERE.

    For example:
    mysql_query("UPDATE [yourtablename] SET wp_user = '".mysql_real_escape_string(trim($_POST['username']))."' WHERE wp_id = 1");

    The function mysql_real_escape_string and trim are not necessary, but they add some extra flexibility and security.
    Babepedia

    Comment

    Working...