theweirdone Posted June 27, 2006 Share Posted June 27, 2006 Hey, I'm having some trouble with this code:[code]<?phpinclude("dogs.inc");mysql_connect($host,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query = "SELECT song_title FROM Songs";$results = mysql_query($query);while($row = mysql_fetch_assoc($query)){echo "$row['song_title']";}mysql_close();?>[/code]This is in a file called all_songs.inc which is being called by a file called index.php. I can't find the problem. The variables $host, $username, $password and $database are all being stored in the file dogs.inc. I know that they are correct, because i have another file adding files to the database, and it works fine. The database has one table called Songs, with two fields: song_id and song_title. I've tried using the functions mysql_fetch_assoc and mysql_fetch_array. Should I be using a different one? Anyone have any ideas?Oh, and what does the "@" in front of mysql_select_db do?Thanx Quote Link to comment https://forums.phpfreaks.com/topic/12977-mysql-info-display-problem/ Share on other sites More sharing options...
AndyB Posted June 27, 2006 Share Posted June 27, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Hey, I'm having some trouble with this code[/quote]Any particular kind of trouble?The @ suppresses errors - remove it, as I assume you have some kind of error. Quote Link to comment https://forums.phpfreaks.com/topic/12977-mysql-info-display-problem/#findComment-49911 Share on other sites More sharing options...
hackerkts Posted June 27, 2006 Share Posted June 27, 2006 Try to rename dogs.inc to dogs.inc.phpNot sure if this causes the problem. Quote Link to comment https://forums.phpfreaks.com/topic/12977-mysql-info-display-problem/#findComment-50005 Share on other sites More sharing options...
theweirdone Posted June 28, 2006 Author Share Posted June 28, 2006 Sorry, should have been more specific. The thing is, it's suppose to display song titles in the database, but nothing shows, it's blank.I took off the '@', but it still shows nothing. I also renamed 'dogs.inc' to 'dogs.inc.php', and that doesn't help either. I've read through the code a few times, and I can't find the error.Would it help if I showed the code that adds songs to the database? Cause that works fine... Quote Link to comment https://forums.phpfreaks.com/topic/12977-mysql-info-display-problem/#findComment-50527 Share on other sites More sharing options...
wildteen88 Posted June 28, 2006 Share Posted June 28, 2006 Try this:[code]<?phpinclude("dogs.inc");mysql_connect($host,$username,$password) or die("Unable to connnect to mysql: " . mysql_error());mysql_select_db($database) or die( "Unable to select database: " . mysql_error());$query = "SELECT song_title FROM Songs";$results = mysql_query($query) or die("Unable to perform query: <i>" . $query . "</i>: " . mysql_error());while($row = mysql_fetch_assoc($query)){echo "$row['song_title']";}mysql_close();?>[/code]Try running your code again. Do you get any errors? Quote Link to comment https://forums.phpfreaks.com/topic/12977-mysql-info-display-problem/#findComment-50537 Share on other sites More sharing options...
theweirdone Posted June 28, 2006 Author Share Posted June 28, 2006 Still doesn't work... I don't get it... Here's the code to add songs, it might help find the problem...[code]<?phpinclude("dogs.inc.php");$song_title = $_GET['song_title'];mysql_connect($host,$username,$password);mysql_select_db($database) or die( "Unable to select database");$query = "INSERT INTO Songs (song_title) VALUES ('$song_title')";mysql_query($query) or die("Unable to do query");echo "Song $song_title has been added successfully";mysql_close();?>[/code]Hope it helps find the problem... Quote Link to comment https://forums.phpfreaks.com/topic/12977-mysql-info-display-problem/#findComment-50549 Share on other sites More sharing options...
hackerkts Posted June 29, 2006 Share Posted June 29, 2006 Try chaning [code]$query = "INSERT INTO Songs (song_title) VALUES ('$song_title')";[/code][code]$query = "INSERT INTO `Songs` VALUES ('', '$song_title')";[/code]As you wrote this[code]$song_title = $_GET['song_title'];[/code]So let's say example you save the file as addsong.phpPeople can add song by going to [a href=\"http://domain/addsong.php?song_title=Crazy_Frog\" target=\"_blank\"]http://domain/addsong.php?song_title=Crazy_Frog[/a]Crazy_Frog will be added to database.. Quote Link to comment https://forums.phpfreaks.com/topic/12977-mysql-info-display-problem/#findComment-50733 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.