pranjalgoenka Posted February 11, 2014 Share Posted February 11, 2014 dear all my code is showing error as Invalid query: No database selected the code is as follows <?php $dbc = mysql_connect("localhost", "root", "123456"); mysql_select_db("ahamdabad_vpn_ip$", $dbc); $sql = "select main_system from ahamdabad_vpn_ip$"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } $username_array = array(); while($row=mysql_fetch_array($result)) { $username_array[] = "\"".$row[main_system]."\""; } $username_string = implode(",", $username_array); echo $username_string; ?> Link to comment https://forums.phpfreaks.com/topic/286103-problem-in-my-program/ Share on other sites More sharing options...
PravinS Posted February 11, 2014 Share Posted February 11, 2014 mysql_select_db("ahamdabad_vpn_ip$", $dbc); $sql = "select main_system from ahamdabad_vpn_ip$"; "ahamdabad_vpn_ip$" is you database or table name? also it is not good practice to use "$" in database of table name Link to comment https://forums.phpfreaks.com/topic/286103-problem-in-my-program/#findComment-1468453 Share on other sites More sharing options...
pranjalgoenka Posted February 17, 2014 Author Share Posted February 17, 2014 ahamdabad_vpn_ip$ is a table. and i don't think if it matters if we have a $ sign at the last Link to comment https://forums.phpfreaks.com/topic/286103-problem-in-my-program/#findComment-1469198 Share on other sites More sharing options...
gristoi Posted February 17, 2014 Share Posted February 17, 2014 well there is your problem, look at the method mysql_select_db the clue is in the name, you are trying to set the db to use with your table name. set the correct db name. also PravinS is correct, you shouldnt be using variable strings in database connection. this leaves you wide open to sql injection and other vulnerabilities Link to comment https://forums.phpfreaks.com/topic/286103-problem-in-my-program/#findComment-1469205 Share on other sites More sharing options...
pranjalgoenka Posted February 17, 2014 Author Share Posted February 17, 2014 thanks but after correcting that it is showing undefined variable error for main_system in while($row=mysql_fetch_array($result)) { $username_array[] = "\"".$row[main_system]."\""; } Link to comment https://forums.phpfreaks.com/topic/286103-problem-in-my-program/#findComment-1469209 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.