Jump to content

unable to select database


haridak

Recommended Posts

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"


 

<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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.