andrewgarn Posted March 6, 2008 Share Posted March 6, 2008 I created a simple php file which should connect to mySQL and list the contents of a table and echo them onto the page. <html> <head> <title>Show database containing Users</title> </head> <body> <?php $conn = @mysql_connect( 'localhost', 'root', '' ) or die( 'Could not connect to MySQL' ); $rs = @mysql_connect_db( 'singer', $conn ) or die( 'Could not select database' ); $sql = 'SELECT * FROM `owner`' or die('There is a problem with the query' ); $rs = mysql_query( $sql, $conn ) or die('Problem'); while( $row = mysql_fetch_array( $rs ) ) { echo( 'Name: ' . $row['name'] ); echo( 'Address: ' . $row['house'] ); echo( ', ' . $row['street'] ); echo( ', ' . $row['town'] ); echo( ', ' . $row['county'] ); echo( ', ' . $row['country'] ); echo( ', ' . $row['postcode'] ); echo( 'Email: ' . $row['email'] ); echo( 'Phone Number: ' . $row['phone'] ); echo( 'Mobile Number: ' . $row['mobile'] ); } ?> <p>Test</p> </body> </html> When i run the page I can see nothing, and when I view the source code i see this: <html> <head> <title>Show database containing Users</title> </head> <body> Any help you can give me would be appreciated. I am running an Apache server with mySQL, both installed using a program called XAMPP Thanks Andrew Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 6, 2008 Share Posted March 6, 2008 I'm not the world's greatest with syntax, but try replacing echo( 'Name: ' . $row['name'] ); echo( 'Address: ' . $row['house'] ); echo( ', ' . $row['street'] ); echo( ', ' . $row['town'] ); echo( ', ' . $row['county'] ); echo( ', ' . $row['country'] ); echo( ', ' . $row['postcode'] ); echo( 'Email: ' . $row['email'] ); echo( 'Phone Number: ' . $row['phone'] ); echo( 'Mobile Number: ' . $row['mobile'] ); with echo "Name: $row['name']"; echo "Address: $row['house']"; echo "$row['street']"; echo "$row['town']"; echo "$row['county']"; echo "$row['country']"; echo "$row['postcode']"; echo "Email: ' . $row['email'] ); echo "Phone Number: ' . $row['phone'] ); echo "Mobile Number: $row['mobile']"; If it works, you can play with it to format it how you want, not sure this is the problem 100% but see if it works. Quote Link to comment Share on other sites More sharing options...
bpops Posted March 6, 2008 Share Posted March 6, 2008 Just to check that php is set up correctly, why don't you make this file and run it: <body> <?php phpinfo(); ?> </body> Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted March 6, 2008 Author Share Posted March 6, 2008 I know php and mysql are set up correctly as I previously made a php script which lets the user add tables. I'll try those changes and get back to you Quote Link to comment Share on other sites More sharing options...
revraz Posted March 6, 2008 Share Posted March 6, 2008 Remove the @ error suppression tags Use mysql_error() after queries to see if there are problems with the query. Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted March 6, 2008 Author Share Posted March 6, 2008 aebstract - your code can't be right surely? as it mixes up the text with variable names inside quotations? Anyway i tried it, it didnt work Revraz - i removed the @before the first two commands and got this: Fatal error: Call to undefined function mysql_connect_db() in C:\Server\XAMPP\htdocs\owner.php on line 13 Line 13 and 14: $rs = mysql_connect_db( 'singer', $conn ) or die( 'Could not select database' ); Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 6, 2008 Share Posted March 6, 2008 read the sticky on this Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks for that, read the sticky. found a php.ini file in C:\Server\XAMPP\php As far as i can see the the things in the sticky were already done? extension_dir = "C:\Server\XAMPP\php\ext\" extension=php_mysql.dll (no semi colon at the start) Any other suggestions? here is a link to my php.ini file http://idire.no-ip.org/php.ini.txt Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 6, 2008 Share Posted March 6, 2008 <?php phpinfo(); ?> see what it says for the mysql functions Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted March 6, 2008 Author Share Posted March 6, 2008 http://idire.no-ip.org/test.php Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 6, 2008 Share Posted March 6, 2008 it looks to be missing a few things in the config, if its not your server contact your admin on fixing this Quote Link to comment Share on other sites More sharing options...
revraz Posted March 6, 2008 Share Posted March 6, 2008 Restart the web server if you haven't yet. Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted March 6, 2008 Author Share Posted March 6, 2008 it looks to be missing a few things in the config, if its not your server contact your admin on fixing this Its mine, however I just noticed its loaded a different php file to the one I edited. I will edit the php file in C:\windows and see if it helps? Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 6, 2008 Share Posted March 6, 2008 andrew, you can mix text and variables in the same echo, why not? $var1 = HI; $var2 = BYE; echo "lalala $var1 lalala $var2"; Would display - lalala HI lalala BYE O.o Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 6, 2008 Share Posted March 6, 2008 andrew, you can mix text and variables in the same echo, why not? The error is in the mysql config right now Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted March 6, 2008 Author Share Posted March 6, 2008 Here is my windows php.ini http://idire.no-ip.org/php.ini.windows.txt Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 6, 2008 Share Posted March 6, 2008 Urm looks like a simple typo problem to me mysql_connect_db should be mysql_select_db Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted March 6, 2008 Author Share Posted March 6, 2008 Urm looks like a simple typo problem to me mysql_connect_db should be mysql_select_db Wow thanks, I can't believe I didnt notice that. I've only been doing php for a week Thanks! problem solved Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 6, 2008 Share Posted March 6, 2008 Yeah and I wasn't offering a solution (obviously) was just letting him know he can do that. 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.