haridak Posted February 20, 2014 Share Posted February 20, 2014 Hi, I'm try to develop the UI for a search engine. Connection the sql server is successfully, however, I keep getting the message no database selected. pasting the entire code below.I'm highlighting the problematic code in blue. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Search Engine</title> </head> <body> <center> <h2>Search Engine</h2> <FORM action="./search2.php" method = "GET"> <input type="text" name="k" size="50"/> <input type="submit" value="search"/> </FORM> <?php $link = mysqli_connect("servername", "username","password","database"); $k=0; $k = $_GET['k']; $terms = explode(",",$k); $query = "SELECT * FROM pagestable WHERE "; for($i=0;$terms[$i]!=null;$i++) { if($i==1) $query.=" OR doc_title like '%$terms[$i]%' "; else $query.="doc_title like '%$terms[$i]%' "; } $nuwrows=0; $sql = mysql_query($query); echo $query; if($sql===false) { var_dump(mysql_error()); } $numrows = mysql_num_rows($query); if($nuwrows>0) { while($row = mysql_fetch_assoc($query)) { $id = $row["doc_id"]; $title = $row["doc_title"]; $link = $row["doc_link"]; $other = $row["other"]; echo "<h2><a href ='$link''>$title</a> </h2>"; echo "$other"; } } else echo "no results found"; mysqli_close($link); ?> <hr> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/286354-unable-to-select-database/ Share on other sites More sharing options...
requinix Posted February 20, 2014 Share Posted February 20, 2014 As you've highlighted, you're using mysqli_connect() in one place and mysql_* functions in the rest. Which means the default username/password combination is valid to connect to your database (since the mysql_* functions did that automatically since you tried to use them without connecting first) and you shouldn't let that happen. Quote Link to comment https://forums.phpfreaks.com/topic/286354-unable-to-select-database/#findComment-1469737 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.