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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.