adamriley Posted July 9, 2010 Share Posted July 9, 2010 error = no database selected from mysql_error() "mysql_select_db("report", $con);" does that not select the database list.php <?php require($_SERVER['DOCUMENT_ROOT'] ."/mysql.php"); // connect to mysql server /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ mysql_select_db("report", $con); $query="SELECT url,ref FROM report"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=student value=''>Student Name</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[id]>$nt[name]</option>"; /* Option values are added by looping through the array */ } echo "</select>"; // Closing of list box echo mysql_error(); ?> mysql.php <?php $con = mysql_connect("localhost","all",""); if (!$con) { die('Could not connect: ' . mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/207277-no-database-selected-mysql/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2010 Share Posted July 9, 2010 mysql_select_db() could be failing if "report" is not your database name or the permissions are not set for the user you connected with. You can also put some error checking logic in your code to make sure - if(!mysql_select_db("report", $con)) { die('Could not select db: ' . mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/207277-no-database-selected-mysql/#findComment-1083763 Share on other sites More sharing options...
adamriley Posted July 9, 2010 Author Share Posted July 9, 2010 one of my stupid moments its name is "reports" but I now have a problem in that the listbox does not have any info html reply <select name=student value=''>Student Name</option><option value=></option><option value=></option><option value=></option><option value=></option></select> Quote Link to comment https://forums.phpfreaks.com/topic/207277-no-database-selected-mysql/#findComment-1083768 Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2010 Share Posted July 9, 2010 If you are referring to the query in the start of this thread, you are selecting url,ref, but those fields are not what you are using in the rest of the code. Quote Link to comment https://forums.phpfreaks.com/topic/207277-no-database-selected-mysql/#findComment-1083769 Share on other sites More sharing options...
adamriley Posted July 9, 2010 Author Share Posted July 9, 2010 Is there any chance you can explain on what you mean : I am trying to select the "url" field in the table "report" is there any chance of example please Quote Link to comment https://forums.phpfreaks.com/topic/207277-no-database-selected-mysql/#findComment-1083774 Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2010 Share Posted July 9, 2010 echo "<option value=$nt[id]>$nt[name]</option>"; ^^^ This is the code that is using what you retrieved from the query. I only see an 'id' and a 'name' field, neither of which is what you actually selected in the query. Quote Link to comment https://forums.phpfreaks.com/topic/207277-no-database-selected-mysql/#findComment-1083776 Share on other sites More sharing options...
adamriley Posted July 9, 2010 Author Share Posted July 9, 2010 Thanks very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/207277-no-database-selected-mysql/#findComment-1083777 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.