rubiks Posted December 20, 2006 Share Posted December 20, 2006 hello there i am new to all of this and i trying to display recods from the database i have created and i am having errors[code] <? //connect to mysql $db_gigs=mysql_connect("localhost","web22-XXX","XXX if (!$db_gigs) { // db error function echo db_error("$db_gigs"); die(); } //select which database you want to edit mysql_select_db("gigs"); //select the table $result = mysql_query("select * from gigs"); //grab all the content while($r=mysql_fetch_array($result)){ //the format is $variable = $r["nameofmysqlcolumn"]; $id=$r["id"]; $event=$r["event"]; $venue=$r["venue"]; $date=$r["date"]; $rating=$r["rating"]; //display the row echo "$id <br> $event <br> $venue <br> $date | $rating <br />"; } ?>[/code]Thats what i have now and i am getting a error which says [quote]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/reesweb.co.uk/public_html/mattbay/music.php on line 38[/quote]Any ideasthanks Matthew Link to comment https://forums.phpfreaks.com/topic/31364-displaying-database-records/ Share on other sites More sharing options...
Orio Posted December 20, 2006 Share Posted December 20, 2006 1) It's not a good idea to show your user and pass for the database. Remove it.2) Try this, and post the error you get:[code]<?php$db_gigs=mysql_connect("localhost","XXX","XXX") or die(mysql_error());mysql_select_db("gigs") or die(mysql_error());$result = mysql_query("select * from gigs") or die(mysql_error());while($r=mysql_fetch_array($result)){ $id=$r['id']; $event=$r['event']; $venue=$r['venue']; $date=$r['date']; $rating=$r['rating']; echo "$id <br> $event <br> $venue <br> $date | $rating <br />";}?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/31364-displaying-database-records/#findComment-145109 Share on other sites More sharing options...
rubiks Posted December 20, 2006 Author Share Posted December 20, 2006 whops cheers forgot about that i get an error ofAccess denied for user 'web22-matthew-1'@'%' to database 'gigs' Link to comment https://forums.phpfreaks.com/topic/31364-displaying-database-records/#findComment-145118 Share on other sites More sharing options...
Orio Posted December 20, 2006 Share Posted December 20, 2006 That means that either the user/password combination is wrong, or the user 'web22-matthew-1' doesnt have premessions to manipulate the database.Orio. Link to comment https://forums.phpfreaks.com/topic/31364-displaying-database-records/#findComment-145119 Share on other sites More sharing options...
rubiks Posted December 20, 2006 Author Share Posted December 20, 2006 ok cheers i will look into it thanks very much matt Link to comment https://forums.phpfreaks.com/topic/31364-displaying-database-records/#findComment-145123 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.