NovaArgon Posted June 12, 2008 Share Posted June 12, 2008 This is my first time working with php and databases and I would like some advice trying to connect them. This is my database table fields http://www.tarantuladatabase.com/tf.jpg This is my field values http://www.tarantuladatabase.com/fv.jpg I am using two php files one of them is called connect.php and it only has the information to connect to my database. The other files is called echo.php. The form is at http://www.tarantuladatabase.com/assets/pages/search.html When I try and connect I am getting this error message Warning: include(includes/connect.php) [function.include]: failed to open stream: No such file or directory in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 38 Warning: include() [function.include]: Failed opening 'includes/connect.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 38 Warning: mysql_query() [function.mysql-query]: Access denied for user 'e0120590'@'localhost' (using password: NO) in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 40 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 40 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 43 Warning: mysql_close(): no MySQL-Link resource supplied in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 48 I am kinda stuck right here so any advice would be greatly appreciated. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted June 12, 2008 Share Posted June 12, 2008 on line 38 of /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php, there is No such file or directory as includes/connect.php Quote Link to comment Share on other sites More sharing options...
xtopolis Posted June 12, 2008 Share Posted June 12, 2008 It can't find the include file. Make sure the path you supply it "includes/connect.php" is referenced correctly to the location of the script running it. A Temporary test might be to supply it the FQDN , like include("http://www.tarantuladatabase.com/path/to/connect.php"); to see if it works, then if it does, work on getting the "../includes/connect.php" type path correct. Solve that first and the mysql stuff should go away. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 12, 2008 Share Posted June 12, 2008 just a quick word of advice NovaArgon next time you put up pics of your phpmyadmin black out the address. *ya don't have to login to phpmyadmin Quote Link to comment Share on other sites More sharing options...
NovaArgon Posted June 12, 2008 Author Share Posted June 12, 2008 Thanks so much for all the advice It looks like that was the problem. I have a new error message so I think I am connected fine and now the problems are just in the echo.php file. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 43 Here we go lol Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 12, 2008 Share Posted June 12, 2008 That would suggest there is an error with your query. Add or die(mysql_error()) after your mysql_query calls, eg mysql_query('your query') or die(mysql_error()) ; Quote Link to comment Share on other sites More sharing options...
NovaArgon Posted June 13, 2008 Author Share Posted June 13, 2008 Ok guys no more error messages! 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 <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. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 13, 2008 Share Posted June 13, 2008 just create a php file to submit all the data in the form... I would do something like this... first create an array that holds the 113 values.. $genus = array ( 'item1', 'item2', 'ECT..', ); //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 112 times while($i<=112) { mysql_query($sql,$con); $i++; } keep in mind this is simply an example. you will have to fill in the gaps here with full code. once you have all the code in place nav to the file in your browser and bam.. database filled. Quote Link to comment Share on other sites More sharing options...
NovaArgon Posted June 13, 2008 Author Share Posted June 13, 2008 Thanks so much how does this look? <!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 ( 'Acanthopelma', 'Acanthoscurria', 'Annandaliella', 'Anoploscelus', 'Aphonopelma', 'Augacephalus', 'Avicularia', 'Batesiella', 'Bonnetina', 'Brachionopus', 'Brachypelma', 'Cardiopelma', 'Catumiri', 'Ceratogyrus', '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', 'Selenogyrus', '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 114 times while($i<=114) { mysql_query($sql,$con); $i++; } </body> </html> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 13, 2008 Share Posted June 13, 2008 Change //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 114 times while($i<=114) { mysql_query($sql,$con); $i++; } to foreach($genus as $value) { $sql = "INSERT INTO tablename (genus) VALUES ($value)"; mysql_query($sql, $con); } Also make sure you have connected to your mysql server/database too before running the code. Quote Link to comment Share on other sites More sharing options...
NovaArgon Posted June 13, 2008 Author Share Posted June 13, 2008 ok just like this <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 } ?> Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted June 13, 2008 Share Posted June 13, 2008 this: 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 } is the same as this: /* while($i<=110) { mysql_query($sql,$con); $i++; }*/ Quote Link to comment Share on other sites More sharing options...
NovaArgon Posted June 13, 2008 Author Share Posted June 13, 2008 How long should it take to show up in my phpmyadmin? this is exactly what I posted <?php include("connect.php"); $genus = array ( 'Aphonopelma', 'Augacephalus', 'Avicularia', 'Batesiella', 'Bonnetina', 'Brachionopus', 'Brachypelma', 'Cardiopelma', 'Catumiri', 'Ceratogyrus', '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', 'Selenogyrus', '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 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? Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted June 13, 2008 Share Posted June 13, 2008 that could be it.... this will tell you: after every thing having to do with mysql, use mysql_query('your query', $con) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 13, 2008 Share Posted June 13, 2008 You're not passing the query to mysql_query function. You have it commented out //mysql_query($sql); // Uncomment when your ready for the real deal Remove the // at the start of the line and your query will execute. Just echo'ing $sql will not perform the query. Also any reason why you didn't use my code suggestion earlier? Quote Link to comment Share on other sites More sharing options...
NovaArgon Posted June 13, 2008 Author Share Posted June 13, 2008 I'm sorry I thought I was using your code ??? I must have got it mixed up when I was trying to put it into dreamweaver. Warning: mysql_query() [function.mysql-query]: Access denied for user 'e0120590'@'localhost' (using password: NO) in /home/e0120590/public_html/tarantuladatabase.com/assets/php/fd.php on line 138 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/e0120590/public_html/tarantuladatabase.com/assets/php/fd.php on line 138 INSERT INTO common_traits(genus) VALUES ('Batesiella') Let me look at my code again and see where I missed it. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 13, 2008 Share Posted June 13, 2008 Whats in connect.php looks like you havn't connected to MySQL properly. Is e0120590 your mysql username? PHP is trying to connect to mysql using e0120590 as the username with no password. Quote Link to comment Share on other sites More sharing options...
NovaArgon Posted June 13, 2008 Author Share Posted June 13, 2008 no thats the table prefix I dont know if I need it. I just alwas had to use it when connecting to the database with a forum. <? /*--------- DATABASE CONNECTION INFO---------*/ $hostname="localhost"; $mysql_login="e0120590_tester"; $mysql_password="**Hidden**"; $database="e0120590_tarantuladatabase"; // connect to the database server if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){ die("Can't connect to database server."); }else{ // select a database if (!(mysql_select_db("$database",$db))){ die("Can't connect to database."); } } ?> Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted June 13, 2008 Share Posted June 13, 2008 you're making your connection to complicated.. just use this: mysql_connect("localhost", "username", "password") or die(mysql_error()); it does everything your code does... but its simplier Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 13, 2008 Share Posted June 13, 2008 That code appears to be fine. No problems there. Seems strange why mysql_query is giving that error, as that error would show if the code in connect.php failed to connect to mysql. Could you post the code you're using in fd.php here Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted June 13, 2008 Share Posted June 13, 2008 in your previous code you are doing this: mysql_query('your query') or die(mysql_error()) where as with your code you just posted, you need to have this: mysql_query('your query', $db) or die(mysql_error()) OR you just remove the $db = from your connect.php, (be sure to remove the $db from the databse select too) that would make the connection over the entire page, so theres no need to repeat it (this is what i do) Quote Link to comment Share on other sites More sharing options...
NovaArgon Posted June 13, 2008 Author Share Posted June 13, 2008 SWEET I got it now it worked thank you guys so much for all the help !!!! Man you guys rock! Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted June 13, 2008 Share Posted June 13, 2008 . Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted June 13, 2008 Share Posted June 13, 2008 seriously? dreamweaver? ??? :-\ 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.