FutureCoder Posted August 23, 2007 Share Posted August 23, 2007 Hello My problem is with the code below: <?php $db = mysql_connect("localhost"); mysql_select_db("menagerie", $db); $query = "select * from animals"; $result = mysql_query($query); $table = mysql_field_table($result, 0); echo $table; This code is supposed to output the name of the table named in the code(animals table from a MySQL database called menagerie). It is exactly like the code in the tutorial I'm going thru but doesn't output anything. What am I doing wrong? And a question: I find that when I run scripts and then make corrections or changes, if I run in PHP Coder IDE sometimes the change does not happen immediately so the output will be the same as before a couple of times until I see the proper output or it will "take" in the coder ide but not in the browser immediately and vice versa. What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/66387-newbie-phpmysql-problem-question/ Share on other sites More sharing options...
phpSensei Posted August 23, 2007 Share Posted August 23, 2007 why don't you just use mysql_fetch_assoc($result) Quote Link to comment https://forums.phpfreaks.com/topic/66387-newbie-phpmysql-problem-question/#findComment-332240 Share on other sites More sharing options...
uwannadonkey Posted August 23, 2007 Share Posted August 23, 2007 do you have any passwords or such to your db? Quote Link to comment https://forums.phpfreaks.com/topic/66387-newbie-phpmysql-problem-question/#findComment-332241 Share on other sites More sharing options...
Daleeburg Posted August 23, 2007 Share Posted August 23, 2007 This is a little snippet of code i use on every project that will save you a lot of time and trouble. <?php $db_host = "localhost"; $db_user = ""; $db_password = ""; $db_name = ""; $connection = mysql_connect( $db_host, $db_user , $db_password) or die("Error Connecting"); mysql_select_db($db_name); ?> If you put that in a separate file and just do a require() it will save you a lot of time. As for your code, i think you need to specify a user. ~D Quote Link to comment https://forums.phpfreaks.com/topic/66387-newbie-phpmysql-problem-question/#findComment-332268 Share on other sites More sharing options...
FutureCoder Posted August 23, 2007 Author Share Posted August 23, 2007 BTY, Thanks for responding quickly! I really appreciate it! The suggestions didn't work but I'm probably using them wrong. More suggestions would be greatly welcomed and appreciated! "why don't you just use mysql_fetch_assoc($result)" phpSensei That didn't work but thanks. "do you have any passwords or such to your db?" uwannadonkey I have a password to get into the MySQL Command line environment but none for any particular db's. "<?php $db_host = "localhost"; $db_user = ""; $db_password = ""; $db_name = ""; $connection = mysql_connect( $db_host, $db_user , $db_password) or die("Error Connecting"); mysql_select_db($db_name); ?> If you put that in a separate file and just do a require() it will save you a lot of time. As for your code, i think you need to specify a user. ~D" Daleeburg That also didn't work but thanks. Could you please explain 'specify a user'. Quote Link to comment https://forums.phpfreaks.com/topic/66387-newbie-phpmysql-problem-question/#findComment-332315 Share on other sites More sharing options...
syngod Posted August 23, 2007 Share Posted August 23, 2007 I have used that same tutorial and found that i forgot to turn the mysql.dll file in the php.ini that may be the cause. Quote Link to comment https://forums.phpfreaks.com/topic/66387-newbie-phpmysql-problem-question/#findComment-332324 Share on other sites More sharing options...
Daleeburg Posted August 23, 2007 Share Posted August 23, 2007 by specify user i meant you need to put in the user name and password that you need to get into. <?php $db_host = "localhost"; $db_user = "[put your user name here, most likely 'root']"; $db_password = "[put your password here]"; $db_name = "[put the database name here]"; $connection = mysql_connect( $db_host, $db_user , $db_password) or die("Error Connecting"); mysql_select_db($db_name); ?> save that to file called "config.php" then at the top of the page with the query put this require('config.php'); so the final page would e something like this. <?php require('config.php'); $query = "select * from animals"; $result = mysql_query($query); $table = mysql_field_table($result, 0); echo $table; ?> Quote Link to comment https://forums.phpfreaks.com/topic/66387-newbie-phpmysql-problem-question/#findComment-332328 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.