No database selected error mysql php -


i trying connect website database "no database selected" error, tried finding solution did not find anything. code is:

    <?php      define('db_name', 'test');     define('db_uesr', '********');     define('db_password', '********');     define('db_host', '********');      $link = mysql_connect(db_host, db_uesr, db_password);      if (!$link) {         die('could not connect: ' . mysql_error());     }      $db_selected = mysql_select_db(db_name, $link);      if (!db_selected) {         die('can\'t use name' . db_name . ' : ' . mysql_error());     }      echo 'connected ';      $value = $_post['naam'];      $sql = "insert naam (test) values ('$value')";      if (!mysql_query($sql)) {         die('error: ' . mysql_error());     }      echo 'uploaded ';      ?> 

the exact massage thad displayed on page is:

connected error: no database selected 

i hope can me, new web site.

you first need change if (!db_selected) if (!$db_selected) see if select succesfully.

also, might want check mysql_error() after selecting database. might have insufficient privileges select database.

afterwards, please check sql injection problems have, stated in comments.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -