Forum Moderators: coopster

Message Too Old, No Replies

Script is not communicating with database.

Cant find the error.

         

dkin

6:05 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



I have an item database that was working fine last week but I had to move a few things around and change a few field names, now it will not write to the database.

I have been looking over the code for a few days and I cannot find what is wrong.

This is my code.

Here is my form.

<form enctype='multipart/form-data' name='add_item' action='modules.php?name=$module_name&file=insert' method='post'>
<b>Description</b>
Item Name <input type=text name='ItemName'>

Item Slot
<select name='ItemSlot'>
<option value='Unknown'>Unknown
<option value='Head'>Head
</select>

Item Level
<select name='ItemLevel'>
<option value='1'>1
<option value='2'>2
</select>

No Trade
<input type=radio name='NoTrade' value='Yes'>Yes
<input type=radio name='NoTrade' value='No'>No

Lore
<input type=radio name='Lore' value='Yes'>Yes
<input type=radio name='Lore' value='No'>No

Added Attributes

Item Hp <input type=text name='Hp'>

Dur <input type=text name='Dur'>

Weapon Type
<select name='WeaponType'>
<option value=''>Not a Weapon
<option value='Unknown'>Unknown
<option value='2 HB'>2 HB
<option value='Range'>Range
</select>

Damage <input type=text name='Damage'>
Hp <input type=text name='HpMax'>
Range <input type=text name='Rang'>
Str <input type=text name='Str'>
Sta <input type=text name='Sta'>
Agi <input type=text name='Agi'>
Dex <input type=text name='Dex'>
Wis <input type=text name='Wis'>
Int <input type=text name='Intel'>
Cha <input type=text name='Cha'>
AC <input type=text name='AC'>
Power <input type=text name='Power'>
HoT <input type=text name='HoT'>
PoT <input type=text name='PoT'>
PR <input type=text name='PR'>
DR <input type=text name='DR'>
FR <input type=text name='FR'>
CR <input type=text name='CR'>
LR <input type=text name='LR'>
AR <input type=text name='AR'>

<b>Classes</b>
War <input type=checkbox name='Class[]' value='War'>
All Classes <input type=checkbox name='Class[]' value='All'>
No Classes <input type=checkbox name='Class[]' value='None'>

<b>Races</b>
Hum <input type=checkbox name='Race[]' value='Hum'>
All Races <input type=checkbox name='Race[]' value='All'>
No Races <input type=checkbox name='Race[]' value='None'>

<b>Item Description</b>
<textarea name='ItemDescription' rows=5 cols=20></textarea>

<b>Item Effects</b>
<textarea name='ItemEffects' rows=5 cols=20></textarea>

<b>Acquired</b>
<input type=radio name='Acquired' value='Unknown'>Unknown
<input type=radio name='Acquired' value='Monster Drop'>Monster Drop
<input type=radio name='Acquired' value='Player Crafted'>Player Crafted

<b>Mob or NPC Name</b>
<input type=text name='MoborNPCName'>

<b>Zone</b>
<input type=text name='Zone'>

<input type=submit value='Submit Form'>
</form>

This is my processer.

$classes = "";
for($i=0;$i<sizeof($Class);$i++)
{
if($classes=="")
$classes = $Class[$i];
else
$classes = $classes.", ".$Class[$i];
}

$races = "";
for($i=0;$i<sizeof($Race);$i++)
{
if($races=="")
$races = $Race[$i];
else
$races = $races.", ".$Race[$i];
}

$link = mysql_connect("localhost","*****","*****");
mysql_select_db("*****",$link);
$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);

OpenTable();
echo"<h2>Thank you for submitting $ItemName.</h2>
Please click the link to return to <a href='http://www.example.com'>http://www.example.com</a>
<table width=50%>
Item Name: $ItemName
Item Slot: $ItemSlot
Item Level: $ItemLevel
No Trade: $NoTrade
Lore: $Lore
Hp: $HpMax
Dur: $Dur
Weapon Type: $WeaponType
Damage: $Damage
Range: $HpMax
Range: $Rang
Str: $Str
Sta: $Sta
Agi: $Agi
Dex: $Dex
Wis: $Wis
Int: $Intel
Cha: $Cha
AC: $AC
Power: $Power
HoT: $HoT
PoT: $PoT
PR: $PR
DR: $DR
FR: $FR
CR: $CR
LR: $LR
AR: $AR
Classes: $classes
Races: $races
Item Description: $ItemDescription
Item Effects: $ItemEffects
Acquired: $Acquired
Mob or NPC Name: $MoborNPCName
Zone: $Zone
;

Anyone see anything?

[edited by: jatar_k at 6:48 pm (utc) on June 29, 2004]
[edit reason] stripped the code down [/edit]

dkin

6:06 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



Jatar can you please edit this so that the [code] is working and it does not span 2000 pixels.

jatar_k

6:30 pm on Jun 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I am working on the edit, that's a bit too much code

first try using a die statement on your query and see what error message comes from mysql

mysql_query($query) or die (mysql_error());

and then see if that gives you some more info.

<added>sorry typo

[edited by: jatar_k at 6:49 pm (utc) on June 29, 2004]

dkin

6:42 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



no message it shows everything thatit should. But it is just not being written to the db.

jatar_k

6:49 pm on Jun 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



did you change the line I mentioned?

change
mysql_query($query);

that you have in your processor to

mysql_query($query) or die ("query died: " . mysql_error());

you can also change these lines
$link = mysql_connect("localhost","*****","*****") or die ("couldnt connect: " . mysql_error());
mysql_select_db("*****",$link) or die ("couldnt select db: " . mysql_error());

dkin

7:14 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



your frickin amazing. I guess a little debugging can usually do the trick.

This is my first time ever using php so thank you for your help.

jatar_k

7:28 pm on Jun 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



my pleasure

these little tricks always come in handy and once you learn them they can save a ton of time. It's the learning them that can be hard, especially with out someone to teach you. ;)