Click to See Complete Forum and Search --> : How to add more than one value to a mysql database field at once


Snot
06-13-2008, 11:34 AM
Ok guys no more error messages! ;D

You try it out here (http://www.tarantuladatabase.com/assets/pages/search.html)

I think its connecting with the database even though its not valid code but I'll work on that :D So this is my new code in echo.php

<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 all of the database field values for genus there are a lot of them. I think about 113 give or take

in this pic I have 4 of them added already.

http://www.tarantuladatabase.com/fv.jpg

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 create 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 (http://www.tarantuladatabase.com/assets/pages/submit.html)

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.

legendx
06-13-2008, 11:57 AM
Click the Import tab and select csv. Set your data up in excel and save it as a csv and import through phpmyadmin.

Snot
06-13-2008, 12:22 PM
Would it be easer to do it in php?

something like this?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload</title>
</head>

<body>
$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',
);

//then create a SQL statement variable
$i=0;
$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

while($i<=110)
{
mysql_query($sql,$con);
$i++;
}
</body>
</html>

legendx
06-13-2008, 12:34 PM
<?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
}
?>


I guess I assumed you had more than one required data field in your table.

That code had a lot of syntax errors and a couple logical ones. I've commented out the query function and left a print statement to show what the queries would looks like. Should be able to copy and paste this into any php file and it should work.

Snot
06-13-2008, 12:53 PM
How long should it take to show up in my phpmyadmin?

the only thing I changed was added my connect.php

<body>
<?php
include("connect.php");
$genus = array (

I just get this message on the php page

INSERT INTO common_traits(genus) VALUES ('Aphonopelma')
INSERT INTO common_traits(genus) VALUES ('Augacephalus')
INSERT INTO common_traits(genus) VALUES ('Avicularia')
INSERT INTO common_traits(genus) VALUES ('Batesiella')
INSERT INTO common_traits(genus) VALUES ('Bonnetina')


It repeats over and over for each of the genus

Could I not be connecting to the database?

legendx
06-13-2008, 02:06 PM
...
echo "$sql <br>";
//mysql_query($sql); // Uncomment when your ready for the real deal


Uncomment the query. I left it commented and printed out each query to show what the script was doing.