Cless Posted July 8, 2007 Share Posted July 8, 2007 Hello, I recently created a script that allows me to add information to a table using a form. Every time I try it, it says "Sorry, Data Could Not Be Inserted. Please Review Your Script." Which is the message I made in the script in case of an error. Could anyone find out what the issue is, please? I've looked to over the script many times, changed many things. I've been up all night. I can't find out what the issue is. when I try to use die, the error say "Count doesn't match row one" or something... I forget. I'm not quite sure what that means. Anyways.. <?PHP //Include Configuration File include("config.php"); //Create Variables $PD_Submit= $_POST['PD_Submit']; $PD_Sprite= $_POST['PD_Sprite']; $PD_Num= $_POST['PD_Num']; $PD_Name= $_POST['PD_Name']; $PD_HP= $_POST['PD_HP']; $PD_ATK= $_POST['PD_ATK']; $PD_DEF= $_POST['PD_DEF']; $PD_SPLATK= $_POST['PD_SPLATK']; $PD_SPLDEF= $_POST['PD_SPLDEF']; $PD_SPD= $_POST['PD_SPD']; $PD_EXP= $_POST['PD_EXP']; $PD_Type1= $_POST['PD_Type1']; $PD_Type2= $_POST['PD_Type2']; $PD_Gender= $_POST['PD_Gender']; $PD_Item= $_POST['PD_Item']; $PD_ContestEXP= $_POST['PD_ContestEXP']; $PD_Sprite1= $_POST['PD_Sprite1']; $PD_Sprite2= $_POST['PD_Sprite2']; $PD_Sprite3= $_POST['PD_Sprite3']; $Table_One= "Pokémon_Data"; //Check If Form Is Submitted if (!$PD_Submit) { //PD_Info ?> <HTML> <form method="POST"> <p class="center"><b>Name</b><br /> <input type="text" name="PD_Name" class="BasicInput" /></p> <p class="center"><b>Pokédex Number</b><br /> <input type="text" name="PD_Num" class="BasicInput" /></p> <p class="center"><b>Sprite Code</b><br /> <input type="text" name="PD_Sprite" class="BasicInput" /></p> <p class="center"><b>HP</b><br /> <input type="text" name="PD_HP" class="BasicInput" /></p> <p class="center"><b>Attack</b><br /> <input type="text" name="PD_ATK" class="BasicInput" /></p> <p class="center"><b>Defense</b><br /> <input type="text" name="PD_DEF" class="BasicInput" /></p> <p class="center"><b>Special Attack</b><br /> <input type="text" name="PD_SPLATK" class="BasicInput" /></p> <p class="center"><b>Special Defense</b><br /> <input type="text" name="PD_SPLDEF" class="BasicInput" /></p> <p class="center"><b>Speed</b><br /> <input type="text" name="PD_SPD" class="BasicInput" /></p> <p class="center"><b>Experience Points</b><br /> <input type="text" name="PD_EXP" class="BasicInput" /></p> <p class="center"><b>Type1</b><br /> <input type="text" name="PD_Type1" class="BasicInput" /></p> <p class="center"><b>Type2</b><br /> <input type="text" name="PD_Type2" class="BasicInput" /></p> <p class="center"><b>Gender</b><br /> <input type="text" name="PD_Gender" class="BasicInput" /></p> <p class="center"><b>Item</b><br /> <input type="text" name="PD_Item" class="BasicInput" /></p> <p class="center"><b>Contest Experience Points</b><br /> <input type="text" name="PD_ContestEXP" class="BasicInput" /></p> <p class="center"><b>Sprite Game Code</b><br /> <input type="text" name="PD_Sprite1" class="BasicInput" /></p> <p class="center"><b>Sprite Type Code</b><br /> <input type="text" name="PD_Sprite2" class="BasicInput" /></p> <p class="center"><b>Sprite Frame And Gender Code</b><br /> <input type="text" name="PD_Sprite3" class="BasicInput" /></p> <input type="submit" value="Add Pokémon" name="PD_Submit" class="BasicInput"/> </form> </HTML> <?PHP } //If The Form Was Submitted, Insert Data else { //This Creates The Variable With The Information To Insert $Insert1= "INSERT INTO $Table_One (PD_Name, PD_Num, PD_Sprite, PD_HP, PD_ATK, PD_DEF, PD_SPLATK, PD_SPLDEF, PD_SPD, PD_EXP, PD_Type1, PD_Type2, PD_Gender, PD_Item, PD_ContestEXP, PD_Sprite1, PD_Sprite2, PD_Sprite3) VALUES ('$PD_Name', '$PD_Num', '$PD_Sprite', '$PD_HP', '$PD_ATK', '$PD_DEF', '$PD_SPLATK', '$PD_SPLDEF', '$PD_SPD','$PD_EXP', '$PD_Type1' '$PD_Type2', '$PD_Gender', '$PD_Item', '$PD_ContestEXP', '$PD_Sprite1', '$PD_Sprite2', '$PD_Sprite3')"; //Insert Data if (mysql_query($Insert1,$connect)) { ?> <HTML> <IMG SRC="/IMG/<? echo "$PD_Sprite1/$PD_Sprite2/$PD_Sprite3/$PD_Sprite"; ?>" alt="<? echo "$PD_Name"; ?>"><br> <b><? echo "$PD_Name"; ?></b><br> <b>Pokédex Number:</b> <? echo "$PD_Num"; ?><br> <b>Gender:</b> <? echo "$PD_Gender"; ?><br> <b>Type1:</b> <? echo "$PD_Type1"; ?><br> <b>Type2:</b> <? echo "$PD_Type2"; ?><br> <b>Item:</b> <? echo "$PD_Item"; ?><br> <b>HP:</b> <? echo "$PD_HP"; ?><br> <b>ATK:</b> <? echo "$PD_ATK"; ?><br> <b>DEF:</b> <? echo "$PD_DEF"; ?><br> <b>SPLATK:</b> <? echo "$PD_SPLATK"; ?><br> <b>SPLDEF:</b> <? echo "$PD_SPLDEF"; ?><br> <b>SPD:</b> <? echo "$PD_SPD"; ?><br> <b>EXP:</b> <? echo "$PD_EXP"; ?><br> <b>ContestEXP:</b> <? echo "$PD_ContestEXP"; ?><br><br> Information Successfully Inserted! <a href="/Pcreate.php">Go Back</a>.<br><br> </HTML> <?PHP } else { echo "Sorry, Data Could Not Be Inserted. Please Review Your Script."; } } ?> Yes, I'm sure the table name is correct, the database information is correct (located in config.php), and the sort. Also, each row is created, too. So I'm sure it's not because the rows and tables are missing. =P Anyways, please find the error for me. I'm not able to find it, at all. Sorry if this sounds quite naive, or something. Thanks! Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/ Share on other sites More sharing options...
JP128 Posted July 8, 2007 Share Posted July 8, 2007 What is the error? or is it just a white screen? Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292281 Share on other sites More sharing options...
Cless Posted July 8, 2007 Author Share Posted July 8, 2007 That's the thing, I'm not quite sure what's causing it. Basically, it won't allow me to insert the data into the table. Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292282 Share on other sites More sharing options...
JP128 Posted July 8, 2007 Share Posted July 8, 2007 Also... Is your table name in the database Pokémon_Data, with the accent on the e: "é". $Table_One= "Pokémon_Data"; Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292283 Share on other sites More sharing options...
JP128 Posted July 8, 2007 Share Posted July 8, 2007 Change: //Insert Data if (mysql_query($Insert1,$connect)) { to //Insert Data if (mysql_query($Insert1,$connect) or die(mysql_error()) { Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292284 Share on other sites More sharing options...
hostfreak Posted July 8, 2007 Share Posted July 8, 2007 I am assuming your error is due to you not having a form action. Try: <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292285 Share on other sites More sharing options...
JP128 Posted July 8, 2007 Share Posted July 8, 2007 Forms without an action='' automatically get/post back to themselves. Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292286 Share on other sites More sharing options...
hostfreak Posted July 8, 2007 Share Posted July 8, 2007 Ah, thanks for that information. Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292287 Share on other sites More sharing options...
Cless Posted July 8, 2007 Author Share Posted July 8, 2007 Yah, I tried that earlier. It says Column count doesn't match value count at row 1. Hmm, I tried it putting the action. Doesn't change anything. Yes, the table name is Pokémon_Data. Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292288 Share on other sites More sharing options...
JP128 Posted July 8, 2007 Share Posted July 8, 2007 Yah, I tried that earlier. It says Column count doesn't match value count at row 1. That right there says that your $Insert1 has too many things to insert... Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292289 Share on other sites More sharing options...
Cless Posted July 8, 2007 Author Share Posted July 8, 2007 Oh. I broke it up into two variables. Partly works... It inserts $Insert1. //This Creates The Variable With The Information To Insert $Insert1= "INSERT INTO $Table_One (PD_Name, PD_Num, PD_Sprite, PD_HP, PD_ATK, PD_DEF, PD_SPLATK, PD_SPLDEF) VALUES ('$PD_Name', '$PD_Num', '$PD_Sprite', '$PD_HP', '$PD_ATK', '$PD_DEF', '$PD_SPLATK', '$PD_SPLDEF')"; $Insert2= "INSERT INTO $Table_One (PD_SPD, PD_EXP, PD_Type1, PD_Type2, PD_Gender, PD_Item, PD_ContestEXP, PD_Sprite1, PD_Sprite2, PD_Sprite3) VALUES ('$PD_SPD','$PD_EXP', '$PD_Type1' '$PD_Type2', '$PD_Gender', '$PD_Item', '$PD_ContestEXP', '$PD_Sprite1', '$PD_Sprite2', '$PD_Sprite3')"; //Insert Data if (mysql_query($Insert1,$connect)) { if (mysql_query($Insert2,$connect)) { ?> <HTML> <IMG SRC="/IMG/<? echo "$PD_Sprite1/$PD_Sprite2/$PD_Sprite3/$PD_Sprite"; ?>" alt="<? echo "$PD_Name"; ?>"><br> <b><? echo "$PD_Name"; ?></b><br> <b>Pokédex Number:</b> <? echo "$PD_Num"; ?><br> <b>Gender:</b> <? echo "$PD_Gender"; ?><br> <b>Type1:</b> <? echo "$PD_Type1"; ?><br> <b>Type2:</b> <? echo "$PD_Type2"; ?><br> <b>Item:</b> <? echo "$PD_Item"; ?><br> <b>HP:</b> <? echo "$PD_HP"; ?><br> <b>ATK:</b> <? echo "$PD_ATK"; ?><br> <b>DEF:</b> <? echo "$PD_DEF"; ?><br> <b>SPLATK:</b> <? echo "$PD_SPLATK"; ?><br> <b>SPLDEF:</b> <? echo "$PD_SPLDEF"; ?><br> <b>SPD:</b> <? echo "$PD_SPD"; ?><br> <b>EXP:</b> <? echo "$PD_EXP"; ?><br> <b>ContestEXP:</b> <? echo "$PD_ContestEXP"; ?><br><br> Information Successfully Inserted! <a href="/Pcreate.php">Go Back</a>.<br><br> </HTML> <?PHP } } Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292290 Share on other sites More sharing options...
JP128 Posted July 8, 2007 Share Posted July 8, 2007 kk... in the mysql... type show create table Pokémon_Data; post what that says. Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292292 Share on other sites More sharing options...
Cless Posted July 8, 2007 Author Share Posted July 8, 2007 CREATE TABLE `Pokémon_Data` (\n `PD_Sprite` varchar(255) NOT NULL default 'DP012DPButterfreeF1M.png',\n `PD_Num` bigint(255) NOT NULL default '0',\n `PD_Name` varchar(255) NOT NULL default 'Missingno',\n `PD_HP` bigint(255) NOT NULL default '0',\n `PD_ATK` bigint(255) NOT NULL default '0',\n `PD_DEF` bigint(255) NOT NULL default '0',\n `PD_SPLATK` bigint(255) NOT NULL default '0',\n `PD_SPLDEF` bigint(255) NOT NULL default '0',\n `PD_SPD` bigint(255) NOT NULL default '0',\n `PD_EXP` bigint(255) NOT NULL default '0',\n `PD_Type1` varchar(255) NOT NULL default 'Unknown',\n `PD_Gender` varchar(100) NOT NULL default 'Male',\n `PD_Item` varchar(255) NOT NULL default 'None',\n `PD_ContestEXP` bigint(255) NOT NULL default '0',\n `PD_Sprite1` varchar(255) NOT NULL default 'DP',\n `PD_Sprite2` varchar(255) NOT NULL default 'Normal',\n `PD_Sprite3` varchar(255) NOT NULL default 'F1M',\n `PD_Type2` varchar(255) NOT NULL default 'Default'\n) TYPE=MyISAM Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292293 Share on other sites More sharing options...
JP128 Posted July 8, 2007 Share Posted July 8, 2007 Found it.... change $Insert2 to: (PD_SPD, PD_EXP, PD_Type1, PD_Type2, PD_Gender, PD_Item, PD_ContestEXP, PD_Sprite1, PD_Sprite2, PD_Sprite3) VALUES ('$PD_SPD','$PD_EXP', '$PD_Type1', '$PD_Type2', '$PD_Gender', '$PD_Item', '$PD_ContestEXP', '$PD_Sprite1', '$PD_Sprite2', '$PD_Sprite3')"; Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292295 Share on other sites More sharing options...
Cless Posted July 8, 2007 Author Share Posted July 8, 2007 YES! It worked! Thanks a lot, man! Hold on... I might have found another error. Now $Insert1 won't work. o.O Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292298 Share on other sites More sharing options...
JP128 Posted July 8, 2007 Share Posted July 8, 2007 $Insert1= "INSERT INTO $Table_One (PD_Name, PD_Num, PD_Sprite, PD_HP, PD_ATK, PD_DEF, PD_SPLATK, PD_SPLDEF, PD_SPD, PD_EXP, PD_Type1, PD_Type2, PD_Gender, PD_Item, PD_ContestEXP, PD_Sprite1, PD_Sprite2, PD_Sprite3) VALUES ('$PD_Name', '$PD_Num', '$PD_Sprite', '$PD_HP', '$PD_ATK', '$PD_DEF', '$PD_SPLATK', '$PD_SPLDEF', '$PD_SPD','$PD_EXP', '$PD_Type1' , '$PD_Type2', '$PD_Gender', '$PD_Item', '$PD_ContestEXP', '$PD_Sprite1', '$PD_Sprite2', '$PD_Sprite3')"; //Insert Data if (mysql_query($Insert1,$connect)) { Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292301 Share on other sites More sharing options...
Cless Posted July 8, 2007 Author Share Posted July 8, 2007 Yes! It finally works. Thanks a ton. Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292302 Share on other sites More sharing options...
JP128 Posted July 8, 2007 Share Posted July 8, 2007 no problem... it took awhile to see.. when you make queries... you should format them like this... $sql = ("INSERT INTO table_name VALUES ( '$variable1', '$variable2', '$variable3', '$variable4', '$variable5', '$variable6', '$variable7', '$variable8', )"); When you format it like that, you can see the commas, and notice when they are missing. And, when you have "or die(mysql_error()); it will say something like: error at '' on line 3 so you can find it quicker.. Also when you have INSERT INTO table_name VALUES (field1,field2) ('Field1info','Field2info'); it is the same as: INSERT INTO table_name VALUES ('Field1info','Field2info'); Link to comment https://forums.phpfreaks.com/topic/58904-solved-having-troubles-with-a-script-i-recently-made/#findComment-292305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.