Forum Moderators: coopster
I tried something like this
if ($Item_Name == "$row["Item_Name"]") {
print "That item is already in the database";
}
Now I know this is wrong but if someone could point me in the right direction it would help very much.
//Check if username/email already in use
if (mysql_num_rows($sql) > 0){
print "That's already in use you muppet"'
}
else
{
print "well done you are not a muppet, we are now going to insert your data";
//do sql that inserts the data
}
Hope that gives you an idea or two
$sql = "insert into table (colname) VALUES ('value')";
if ( mysql_query($sql) ) {
echo "Insert succeedinated.";
} elseif ( preg_match('/Duplicate entry/', mysql_error()) ) {
echo "Duplicate data, dude. Didn't do it.";
} else {
echo "Query failed.";
}
$link = mysql_connect("localhost","", "") or die ("couldnt connect: " . mysql_error());
mysql_select_db("",$link) or die ("couldnt select db: " . mysql_error());
$sql = "insert into nuke_item_database (Item_Name) VALUES ('$ItemName')";
if ( mysql_query($sql) ) {
echo "Insert succeedinated.";
} elseif ( preg_match('/Duplicate entry/', mysql_error()) ) {
echo "Duplicate data, dude. Didn't do it.";
} else {
$query="insert into nuke_item_database (Item_Name,Item_Slot,Item_Level,No_Trade,Lore,Hp,Dur,Weapon_Type, Damage,HpMax,Rang,Str,Sta,Agi,Dex,Wis,Intel,Cha,AC,Power,HoT,PoT, PR,DR,FR,CR,LR,AR,Classes,Races,Item_Description,Item_Effects, Acquired,Mob_or_NPC_Name,Zone) values ('".$ItemName."','".$ItemSlot."','".$ItemLevel."','".$NoTrade."', '".$Lore."','".$Hp."','".$Dur."','".$WeaponType."','".$Damage."','". $HpMax."','".$Rang."','".$Str."','".$Sta."','".$Agi."','".$Dex."','". $Wis."','".$Intel."','".$Cha."','".$AC."','".$Power."','".$HoT."','". $PoT."','".$PR."','".$DR."','".$FR."','".$CR."','".$LR."','".$AR."','". $classes."','".$races."','".$ItemDescription."','".$ItemEffects."','". $Acquired."','".$MoborNPCName."','".$Zone."')";
mysql_query($query) or die ("query died: " . mysql_error());
}
[edited by: jatar_k at 7:01 pm (utc) on June 30, 2004]
[edit reason] fixed sidescroll [/edit]
Then timster added that if you ALTER the table so that your Item column has the UNIQUE keyword assigned to it, you wouldn't have to run a SELECT first, simply attempt an INSERT and monitor for error messages.
It doesn't matter if you are trying to INSERT many column names at once or only the unique column by itself (you can do both), as long as the UNIQUE column is in part of your option list and has a unique value, the INSERT will be successful. If a duplicate (NON-UNIQUE) value is attempted, you'll get an error.
This is line 41
$query="insert into nuke_item_database (Item_Name,Item_Slot,Item_Level,No_Trade,Lore,Hp,Dur,Weapon_Type, Damage,HpMax,Rang,Str,Sta,Agi,Dex,Wis,Intel,Cha,AC,Power,HoT,PoT, PR,DR,FR,CR,LR,AR,Classes,Races,Item_Description,Item_Effects, Acquired,Mob_or_NPC_Name,Zone) values ('".$ItemName."','".$ItemSlot."','".$ItemLevel."','".$NoTrade."','". $Lore."','".$Hp."','".$Dur."','".$WeaponType."','".$Damage."','". $HpMax."','".$Rang."','".$Str."','".$Sta."','".$Agi."','".$Dex."','". $Wis."','".$Intel."','".$Cha."','".$AC."','".$Power."','".$HoT."','". $PoT."','".$PR."','".$DR."','".$FR."','".$CR."','".$LR."','".$AR."','". $classes."','".$races."','".$ItemDescription."','".$ItemEffects."','". $Acquired."','".$MoborNPCName."','".$Zone."')";
[edited by: jatar_k at 7:02 pm (utc) on June 30, 2004]
[edit reason] fixed sidescroll [/edit]