I am going to post this as a noob question,

I use this in phpmyadmin to enter data into the database, i know it works right, but i have a question about replacing or updating

here goes

INSERT INTO users (id,mwid,username,level,team,defwin,deflose,notes) VALUES
(148687346, '100000148687346', ' Bang Mike', '903', '51', '5611', '100', ' notes')

My question is this, how can i make it so if the id already exists it will update the username,level,team,defwin( If the new # is = or greater),deflose( If the new # is = or greater)

I have searched and cannot find this answer, i appreciate your help

    you have to first check if id exists

    run a query
    $query=mysql_query(select * from users where id=id_number);

    $rows = mysql_num_rows($query);
    if ($rows == 0) {
    place "INSERT INTO query here";
    } else {
    place "UPDATE query here";
    }

    i'm just a beginner with php, so maybe someone will give you better solution, but for now this should work

      Thanks for your reply, i should of been more clear i am just running my phpadmin and pasting the sql file in there, i would love to make a page on my site where i could just do the same thing, but for now i need to make is so when i paste the SQL if that user already exists it will update the other info, if this is not possible with just a INSERT INTO or UPDATE query i would be happy to do it in php but i am a novice myself

        I totally thanks for the link, but that is waaaaaayyyyyyy beyond my comprehension I am just looking for a simple solution to add to the begining of my sql file so if the user id exists already it replaces the rest of the data except for the 'id'

          Write a Reply...