Skipjackrick Posted February 10, 2008 Share Posted February 10, 2008 I am a beginner php guy but I can figure out most things. I created this Form and when I submit data the result I get doesn't coincide with the data chosen in the form. I get 1 - 0 - - 0 - 0 - 0 - 0 - 0 - 0 - 0 2 - 0 - - 0 - 0 - 0 - 0 - 0 - 0 - 0 3 - 0 - - 0 - 0 - 0 - 0 - 0 - 0 - 0 4 - 0 - - 0 - 0 - 0 - 0 - 0 - 0 - 0 and so on Can anybody help me figure out how to enter the correct data? What am I missing??? I am about 1 cup of coffee short from dropping my computer from the Sears Tower. Anybody ever see the movie Office Space where they went postal on the Copier/printer???? That's how I feel right about now...AHHHHHH!H!!!!H!H!H!H!H <?php #################################################################### ################ DATABASE CONFIGURE ############################## #################################################################### $hostname = "localhost"; $db_user = "********"; $db_password = "********"; $db_table = "submit"; # STOP HERE #################################################################### # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db ("********") or die (mysql_error()); ?> <html> <head> <title>Kayak Wars Submission Form</title> <script type="text/javascript"> //<![CDATA[ // array of possible team in the same order as they appear in the country selection list var teamLists = new Array(5) teamLists["empty"] = ["Select Angler"]; teamLists["1"] = ["Oz", "Skipjack", "Curmit", "Old Salt", "Kip",]; teamLists["2"] = ["Jolly Roger", "Oscar", "Altonr77", "Mythman", "Crazy Yak"]; teamLists["3"] = ["Mako", "Tunakilla", "Jason Bundick", "Brandon Sellers", "Shane Casady"]; teamLists["4"] = ["Lets go", "Crank B8", "Bogdog", "Honky", "da kid from down south"]; /* teamChange() is called from the onchange event of a select element. * param selectObj - the select object which fired the on change event. */ function teamChange(selectObj) { // get the index of the selected option var idx = selectObj.selectedIndex; // get the value of the selected option var which = selectObj.options[idx].value; // use the selected option value to retrieve the list of items from the countryLists array cList = teamLists[which]; // get the team select element via its known id var cSelect = document.getElementById("angler"); // remove the current options from the country select var len=cSelect.options.length; while (cSelect.options.length > 0) { cSelect.remove(0); } var newOption; // create new options for (var i=0; i<cList.length; i++) { newOption = document.createElement("option"); newOption.value = cList[i]; // assumes option string and value are the same newOption.text=cList[i]; // add the new option try { cSelect.add(newOption); // this will fail in DOM browsers but is needed for IE } catch (e) { cSelect.appendChild(newOption); } } } //]]> </script> </head> <body> Kayak Wars Submission Form<hr> <?php if (isset($_REQUEST['Submit'])) { # THIS CODE TELLS MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO $db_table(submit_id, team, angler, species, quantity, kayak, yyyy, mm, dd, water) values ('$submit_id', '$team', '$angler', '$species', '$quantity', '$kayak', '$yyyy', '$mm', '$dd', '$water')"; if($result = mysql_query($sql ,$db)) { echo "Thank you, Your information has been entered into the database"; } else { echo "ERROR: ".mysql_error(); } } else { ?> <form id="form1" name="form1" method="POST" action=""> <input type="hidden" name="submit_id" value="NULL"> <tr> <td><div align="left" class="style2">Team</div></td> <td><label> <select name="team" id="team" onChange="teamChange(this);"> <option value="0">Select a Team</option> <option value="1">Rockstar</option> <option value="2">Plastic Pirates</option> <option value="3">Third Coast Hustlas</option> <option value="4">Wildy</option> </select> </label></td> </tr> <tr> <td width="181"><div align="left" class="style2">Angler</div></td> <td width="309"><label> <select name="angler" id="angler"> <option value="0">Select Angler</option> </select> </label></td> </tr> <tr> <td><div align="left" class="style2">Species</div></td> <td><select name="species" id="species"> <option value="0">Select Species</option> <option value="1">Red Drum</option> <option value="2">Trout</option> <option value="3">Snook</option> <option value="4">Shark</option> <option value="5">Black Drum</option> <option value="6">Snapper</option> <option value="7">King Mackerel</option> <option value="8">Grouper</option> <option value="9">Cobia (Ling)</option> <option value="10">Flounder</option> <option value="11">Tarpon</option> <option value="12">Tripletail</option> <option value="13">Permit</option> <option value="14">Blackfin Tuna</option> <option value="15">Yellowfin Tuna</option> <option value="16">Barracuda</option> <option value="17">Bonefish</option> <option value="18">Dorado</option> <option value="19">Wahoo</option> <option value="20">Billfish</option> </select> <span class="style2"> <label>Quantity</label> </span> <label> <input name="quantity" type="text" id="quantity" size="3" maxlength="2" /> </label></td> </tr> <tr> <td><div align="left" class="style2">Kayak</div></td> <td><select name="kayak" id="kayak"> <option value="0">Select Kayak</option> <option value="1">Malibu 2 XL</option> <option value="2">Malibu 2</option> <option value="3">Cobra Fish N Dive</option> <option value="4">Scrambler XT</option> <option value="5">Speck</option> <option value="6">Hobie</option> </select></td> </tr> <tr> <td><div align="left" class="style2">Date of catch</div></td> <td><select name="yyyy" id="yyyy"> <option value="2008" selected="selected">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> </select> <select name="mm" id="mm"> <option value="00">Select Month</option> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="dd" id="dd"> <option value="00">Select day</option> <option value="01">1</option> <option value="02">2</option> <option value="03">3</option> <option value="04">4</option> <option value="05">5</option> <option value="06">6</option> <option value="07">7</option> <option value="08">8</option> <option value="09">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> </td> </tr> <tr> <td><div align="left" class="style2">Body of Water</div></td> <td><label> <select name="water" id="water"> <option value="0">Select Body of Water</option> <option value="1">Upper Coast</option> <option value="2">Middle Coast</option> <option value="3">Lower Coast</option> </select> </label></td> </tr> <tr> <td colspan="2"><div align="center"> <label> <input type="Submit" name="Submit" id="Submit" value="Submit" /> </label> <label> <input type="reset" name="clear" id="clear" value="Clear" /> </label> </div></td> </tr> </form> <?php } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 10, 2008 Share Posted February 10, 2008 Where are your $_POST vars? Quote Link to comment Share on other sites More sharing options...
schilly Posted February 10, 2008 Share Posted February 10, 2008 Couple things I noticed right away: change $_REQUEST['submit'] to $_POST['submit'] as in your form tag you have method='post' also, none of those variables in your INSERT statement are defined so it will not input any data. You will need to do some like $team = $_POST['team']; $species = $_POST['species']; ... etc. Change that and let us know how it goes. Also echo your INSERT statement so you can verify the SQL string before it gets inserted into the db. Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted February 11, 2008 Author Share Posted February 11, 2008 Thanks guys. I will look up on some tutorials as to what you guys are talking about. I'll let you know what I learn or if I am still stuck. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.