tech291083 Posted September 10, 2006 Report Share Posted September 10, 2006 hi, i have been trying to make the following php script work on fedora 5 os. but it does not show any data from the database. can any one please help. the code has been taken without any change from an online tutorial here. http://www.freewebmasterhelp.com/tutorials/phpmysql/4 so i think it should be ok and the database has also been designed just as mentioned in the tutorial. <? $username="username"; $password="password"; $database="your_database"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM contacts"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>"; $i++; } ?> i have checked mysql database and the data is there but i m getting confused here.help please. thanks. [moved from Terminal Shell commands, etc by spinynorman] Quote Link to comment Share on other sites More sharing options...
ianw1974 Posted September 10, 2006 Report Share Posted September 10, 2006 $username="username";$password="password"; $database="your_database"; Did you replace username with the mysql userid? And password? And your_database? These need to be set to access the database. Quote Link to comment Share on other sites More sharing options...
tech291083 Posted September 10, 2006 Author Report Share Posted September 10, 2006 yes, i did so. but still nothing is displayed in the browser. i have been able to run a simple php page with no problems and this is the first time that i have tried to connect to a mysql database and problems are occuring. i created a database from mysql prompt first and then i set the user privilege using the following command grant all privileges on *.* to root@"localhost" identified by 'thepassword'; and i m logging as root and trying to run the page but nothing is displayed. so i need help. Quote Link to comment Share on other sites More sharing options...
tyme Posted September 11, 2006 Report Share Posted September 11, 2006 tech: is there any data in the database? if all you did was create the database structure and give privilidges, then there is no data in the database and so you don't receive any results. if there was an error, chances are you would get an error message back. if there was no data, $num would be 0, and your while loop would die before it got started. try changing the loop do a do-while and see what happens: do { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>"; $i++; } while ($i < $num) Quote Link to comment Share on other sites More sharing options...
paul Posted September 11, 2006 Report Share Posted September 11, 2006 remove the @ from the begining of mysql_select_db($database) or die( "Unable to select database"); the @ surpresses errors you could also change the connection line to : mysql_connect(localhost,$username,$password) or die ("DAG NAM IT Jethro .. theres no database server"); Quote Link to comment Share on other sites More sharing options...
tech291083 Posted September 11, 2006 Author Report Share Posted September 11, 2006 thanks guys, i did all you suggested but still getting no where so i m gonna do a reintall and let you know when done.thanks again. Quote Link to comment Share on other sites More sharing options...
jlc Posted September 11, 2006 Report Share Posted September 11, 2006 (edited) If you have selinux enabled, you can try the following: # setsebool -P mysqld_disable_trans=1 This disables SELinux from protecting mysqld. If that doesn't work, you can temporarily turn selinux off just for a test. # setenforce 0 0 = permissive 1 = enforcing check the status with # sestatus SELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 20 Policy from config file: targeted This might also have some relevant info on MySQl: http://stanton-finley.net/fedora_core_5_in...otes.html#MySQL Some SELinux info http://fedora.redhat.com/docs/selinux-faq-fc5/en_US/ If turning off SELinux does the trick for you, please file a bug against the policy package. Edited September 11, 2006 by jlc Quote Link to comment Share on other sites More sharing options...
SoulSe Posted September 11, 2006 Report Share Posted September 11, 2006 Might also be useful to know if you are getting any error messages after using Paul's suggestion? Is it just returning a blank page or...? Quote Link to comment Share on other sites More sharing options...
tech291083 Posted September 12, 2006 Author Report Share Posted September 12, 2006 (edited) hi guys, thanks for the suggestions i am trying them now and let you asap. cheers Edited September 18, 2006 by tech291083 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.
Note: Your post will require moderator approval before it will be visible.