Jump to content

pranjalgoenka

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.