adding data to a database using a form? |
adding data to a database using a form? |
NovaArgon |
Jun 13 2008, 10:07 AM
Post
#1
|
Always Need To Learn A New Code Group: Members Posts: 265 Joined: 10-June 07 From: South Carolina Member No.: 3,057 |
Ok guys no more error messages! ;D
You try it out here I think its connecting with the database even though its not valid code but I'll work on that So this is my new code in echo.php CODE <div class="c1"> <table cellspacing="20"> <tr> <th>Habitat</th> <th>Humidity</th> <th>Speed</th> <th>Size</th> <th>Location</th> <th>Aggression</th> </tr> <? include("connect.php"); // now you are connected and can query the database $request = mysql_query("SELECT * FROM common_traits WHERE habitat = \"".$_REQUEST['habitat']."\" AND humidity = \"".$_REQUEST['humidity']."\" AND speed = \"".$_REQUEST['speed']."\" AND size = \"".$_REQUEST['size']."\" AND location = \"".$_REQUEST['location']."\", AND aggression = \"".$_REQUEST['aggression']."\""); // loop through the results with mysql_fetch_array() if ( @mysql_num_rows($row) > 0 ) { while($row = mysql_fetch_array($result)){ echo " <tr> <td>".$row['habitat']."</td> <td>".$row['humidity']."</td> <td>".$row['speed']."</td> <td>".$row['size']."</td> <td>".$row['location']."</td> <td>".$row['aggression']."</td> </tr> "; } } else { echo "<tr><td colspan = 6></td></tr>"; } // don't forget to close the mysql connection mysql_close(); ?> </table> <a href="http://www.tarantuladatabase.com/assets/pages/search.html"><input name="Back" type="button" value="Back" /></a></div> </div> Please correct me if i'm wrong but i think my next step in the project is to create a form that will submit data to my database so that I have something to search? I need to add a all of the database field values for genus there are a lot for them. I think about 113 give or take in this pic I have 4 of them added already. I know there is a way to past them into my sql and submit them all at one time but I don't know the format. What I would like to do is creat the file in a .txt file and then copy and past it to the database once its all compiled. Is there any way you can give me any example of the code I would need to submit that to the database? I have also added a species field that will be typed in by my users when they submit a new species into the database. but before I start doing all this I just wanted to check and make sure it was necessary. Just to explain how the submission form will work you select a genus from the drop down then type in the species name in the text box. Click one of each of the bullet points and click the tarantula submission button. This is the submission form I want that to create a new tarantula in my database under the selected genus. Is this adding up? Thanks so much for all the help and advice. This post has been edited by NovaArgon: Jun 13 2008, 10:12 AM |
NovaArgon |
Jun 13 2008, 11:16 AM
Post
#2
|
Always Need To Learn A New Code Group: Members Posts: 265 Joined: 10-June 07 From: South Carolina Member No.: 3,057 |
I'm going to try this...
CODE <body> <?php include("connect.php"); $genus = array ( 'Aphonopelma', 'Augacephalus', 'Avicularia', 'Batesiella', 'Bonnetina', 'Brachionopus', 'Brachypelma', 'Cardiopelma', 'Catumiri', 'Cerato*****', 'Chaetopelma', 'Chilobrachys', 'Chromatopelma', 'Citharacanthus', 'Citharischius', 'Citharognathus', 'Clavopelma', 'Coremiocnemis', 'Crassicrus', 'Cratorrhagus', 'Cyclosternum', 'Cyriocosmus', 'Cyriopagopus', 'Cyrtopholis', 'Davus', 'Encyocratella', 'Encyocrates', 'Ephebopus', 'Euathlus', 'Eucratoscelus', 'Eumenophorus', 'Eupalaestrus', 'Euphrictus', 'Grammostola', 'Hapalopus', 'Hapalotremus', 'Haploclastus', 'Haplocosmia', 'Haplopelma', 'Harpactira', 'Harpactirella', 'Hemiercus', 'Hemirrhagus', 'Heteroscodra', 'Heterothele', 'Holothele', 'Homoeomma', 'Hysterocrates', 'Idiothele', 'Iracema', 'Iridopelma', 'Ischnocolus', 'Lampropelma', 'Lasiodora', 'Lasiodorides', 'Loxomphalia', 'Loxoptygus', 'Lyrognathus', 'Mascaraneus', 'Megaphobema', 'Melloina', 'Melloleitaoina', 'Metriopelma', 'Monocentropus', 'Myostola', 'Neostenotarsus', 'Nesiergus', 'Nesipelma', 'Nhandu', 'Oligoxystre', 'Ornithoctonus', 'Orphnaecus', 'Ozopactus', 'Pachistopelma', 'Pamphobeteus', 'Paraphysa', 'Phlogiellus', 'Phoneyusa', 'Phormictopus', 'Phormingochilus', 'Plesiopelma', 'Plesiophrictus', 'Poecilotheria', 'Proshapalopus', 'Psalmopoeus', 'Pseudhapalopus', 'Pseudoligoxystre', 'Pterinochilus', 'Reversopelma', 'Schismatothele', 'Schizopelma', 'Selenobrachys', 'Selenocosmia', 'Seleno*****', 'Selenotholus', 'Selenotypus', 'Sericopelma', 'Sickius', 'Sphaerobothria', 'Stichoplastoris', 'Stromatopelma', 'Tapinauchenius', 'Theraphosa', 'Thrigmopoeus', 'Thrixopelma', 'Tmesiphantes', 'Trichognathella', 'Vitalius', 'Xenesthis', 'Yamia', ); // $sql = "INSERT INTO tablename (genus) VALUES ('".$genus[$i]."')"; //then make you a while loop that will loop through your Insert into query code 110 times -- Edit lol? /* while($i<=110) { mysql_query($sql,$con); $i++; }*/ for ($x=0;$x<count($genus);$x++) { $sql = "INSERT INTO common_traits(genus) VALUES ('".$genus[$x]."')"; echo "$sql <br>"; //mysql_query($sql); // Uncomment when your ready for the real deal } ?> </body> This post has been edited by NovaArgon: Jun 13 2008, 11:46 AM |
Brian Chandler |
Jun 13 2008, 01:12 PM
Post
#3
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
I still think you have grossly underestimated the size of this job. You need to get the basics right first. In particular, you don't need to make a form to add spiders - just add them in phpmyadmin to start with at least.
The organisation of your table needs rethinking. You started with a table called "spider" (?) - quite sensibly - but now you have one called "common_traits". Not clear why, since the entries in this table appear to be spiders. Of course the different fields are _properties_ ("traits" if you like) of spiders. Also, if you want to have a "size" property, for example, you need to enter it in a programming-friendly way. Currently you have (quite long) text strings "4in to 6in..." etc. This means that every spider in this size range has to have exactly the same string, which is error-prone, and wasteful*. Usually things like this are numbers, but since these are only guidelines, I suggest you should decide on a set of codes - just number the size ranges from 1 ... 6 (or similar). Then you will be able to search (e.g.) for "any size up to size 3", by writing some SQL that looks like "WHERE sizecode <= 3" and so on. * "Wasteful". Well, when I was a lad, memory cost money... Same goes for habitats, and so on. |
Brian Chandler |
Jun 13 2008, 01:31 PM
Post
#4
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
QUOTE while($i<=110) That's a terrible idea. PHP has this useful thing called foreach($array as $var) which goes through all elements of the $array in turn as $var, so you don't have to count them. Actually, the best thing would be to put all the genera in a table (called 'genus' probably). You might want to give them properties, but to start with there's nothing wrong with just having a list. This means that you need to write a little function to load them out of the database into an array. |
NovaArgon |
Jun 13 2008, 05:34 PM
Post
#5
|
Always Need To Learn A New Code Group: Members Posts: 265 Joined: 10-June 07 From: South Carolina Member No.: 3,057 |
Well what can say?
Is it to late to change it? I mean damn i feel like everything has been coming together so good and now this. I asked a ton of people how I should do every little detail of my project and no one spoke up and said your data base is all wrong when I was posting pics of how I had it done and asking if its going to do what I want it to do no one said a thing. Now I have the submission form working and submitting spider into the data base I have a protected admin page that allows me to approve and deny users submissions and my next step was to tackle the search function and now I find out it was all a wast of time because the database is crap. I mean what do I do? Im going to take a break for a while this really sucks. I'll post again latter tonight after I cool off. |
Lo-Fi Version | Time is now: 23rd April 2024 - 09:05 AM |