scorpiious Posted April 29, 2007 Share Posted April 29, 2007 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 More sharing options...
xenophobia Posted April 29, 2007 Share Posted April 29, 2007 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 More sharing options...
bubblegum.anarchy Posted April 29, 2007 Share Posted April 29, 2007 use REPLACE instead of INSERT and make sure that the username has a UNIQUE index. Link to comment https://forums.phpfreaks.com/topic/49189-update-or-insert/#findComment-241228 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.