Jump to content

Update Or Insert


scorpiious

Recommended Posts

can someone please tell me how i can do this? i have this code to insert into my db

 

mysql_query("INSERT INTO userdata (username, combat, overall, rank, xp, attack, defence, strength, hp, ranged, prayer, magic, cooking, woodcutting, fletching, fishing, firemaking, `crafting`, smithing, mining, herblore, agility, theiving, slayer, farming, runecraft, hunter, construction) VALUES ('$_GET[user]', '".$cblevel[0]."', '".parselvl(Overall)."', '".parserank(Overall)."', '".parsexp(Overall)."', '".parselvl(Attack)."', '".parselvl(Defence)."', '".parselvl(Strength)."', '".parselvl(Hitpoints)."', '".parselvl(Ranged)."', '".parselvl(Prayer)."', '".parselvl(Magic)."', '".parselvl(Cooking)."', '".parselvl(Woodcutting)."', '".parselvl(Fletching)."', '".parselvl(Fishing)."', '".parselvl(Firemaking)."', '".parselvl(Crafting)."', '".parselvl(Smithing)."', '".parselvl(Mining)."', '".parselvl(Herblore)."', '".parselvl(Agility)."', '".parselvl(Thieving)."', '".parselvl(Slayer)."', '".parselvl(Farming)."', '".parselvl(Runecraft)."', '".parselvl(Hunter)."', '".parselvl(Construction)."')");

 

but if the user already exists it'll just create the same username over again except with different values.. how can i get it so if the username exists it just overwrites the stats?

Link to comment
https://forums.phpfreaks.com/topic/49189-update-or-insert/
Share on other sites

then you must check the username from the database first before inserting new records in it:

 

$qry = mysql_query("SELECT * FROM userdata WHERE username='$_GET[user]'");

if(mysql_num_rows($qry)){
    //user already existed in the database...
    //prompt error...
}else{
    //Username does not exist in database, can be proceed to insert.
    //Place your INSERT sql here.
}

 

Hope this help you.

Link to comment
https://forums.phpfreaks.com/topic/49189-update-or-insert/#findComment-241055
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.