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; ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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]."\""; } 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.