Please I am sorry that I have to ask again this one below, 1st, thought I would like to contribute in solving some problems for people like me too but I haven`t found a thread that I have the knowledge to treat but promise to contribute when found one.

My Problem is here below:
1st: Please can someone give me an idea of search code form,the type of search code is to link names to different websites of which on search form one can type a name it will open the site linked with the name in another tab or window, please help me out.

Dani AI

Generated

This thread asks for a simple search box that maps typed names to external URLs and opens the chosen site in a new tab. pointed toward an autocomplete-style UI and sensible UX (choose on click), and provided a server-side example—but that example uses the old mysql_* functions and needs security and accessibility updates. Below is a modern, safe pattern that combines a JSON suggestion endpoint (server) with a small client-side renderer that produces real links the user can click.

A lightweight server endpoint (use PDO with prepared statements) returns a small JSON array of matching {name,url} rows. The endpoint should validate/allowlist the URL scheme (only http/https) and return only canonical, safe URLs. Example (suggest.php):

<?php
// suggest.php?q=term
if (empty($_GET['q'])) {
  header('Content-Type: application/json; charset=utf-8'); echo '[]'; exit;
}
$q = $_GET['q'] . '%';

$pdo = new PDO('mysql:host=localhost;dbname=sites;charset=utf8mb4','dbuser','dbpass',[
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);

$stmt = $pdo->prepare('SELECT site_Name, site_URL FROM sites WHERE site_Name LIKE :q ORDER BY site_Name LIMIT 10');
$stmt->execute([':q' => $q]);
$rows = $stmt->fetchAll();

$results = [];
foreach ($rows as $r) {
  if (filter_var($r['site_URL'], FILTER_VALIDATE_URL) && preg_match('#^https?://#i',$r['site_URL'])) {
    $results[] = ['name'=>$r['site_Name'],'url'=>$r['site_URL']];
  }
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode($results);

On the client, render the suggestions as a small list of anchors so clicks naturally open a new tab (use target="_blank" plus rel="noopener noreferrer"). This avoids programmatic window.open issues and keeps keyboard/mouse behavior consistent. Example client snippet:

<input id="site-search" type="search" autocomplete="off" placeholder="Search sites">
<ul id="suggestions" role="listbox" aria-label="Search suggestions"></ul>

<script>
const input = document.getElementById('site-search'), list = document.getElementById('suggestions');
input.addEventListener('input', async () => {
  const q = input.value.trim(); list.innerHTML = ''; if (!q) return;
  const res = await fetch('/suggest.php?q=' + encodeURIComponent(q));
  if (!res.ok) return;
  (await res.json()).forEach(it => {
    const li = document.createElement('li');
    const a = document.createElement('a');
    a.textContent = it.name; a.href = it.url; a.target = '_blank'; a.rel = 'noopener noreferrer';
    li.appendChild(a); list.appendChild(li);
  });
});
</script>

Notes and cautions: require a click or explicit Enter to navigate (avoid auto-redirect on typing), filter/validate URLs server-side, use parameterized queries to prevent SQL injection (see OWASP), and follow accessible combobox/listbox patterns for keyboard users. For small static lists, HTML <datalist> is an option. Relevant references: HTML datalist (MDN), PHP PDO manual, OWASP SQL Injection Prevention Cheat Sheet, and the WAI-ARIA autocomplete example (combobox) WAI-ARIA practices.

Recommended Answers

All 2 Replies

What you are talking of is called AUTO-SUGGEST or AUTO-COMPLETE and it's a AJAX request thing.
Here are some tutorials and plug-ins CLICK HERE
Probably you should create your own database of the desired auto-suggestion which are the web addresses and the names you're talking about putted in HTML links and the drop down menu should be modified with these links instead of simple text as it is in the tutorials.
I also suggest that the redirecting to the sites happens on a click not just with typing because wrong auto complete will trigger linking and that leads to undesired behavior.
BR

You could also do something like this:

$con = mysql_connect($dbuser, $dbpass, $dbhost, client_flags = 0, new_link = false);
if (!con)
{
     echo "Database Error";
     die(mysql_error());
}
mysql_select_db($dbname, $con);
?>
Your search for site form goes here
<?php
$sql = "SELECT * FROM sites WHERE siteName = '$_GET["siteName"]'";
$result = mysql_query($sql);
if (!$result)
{
     echo "Database Error";
     die(mysql_error());
}
// Table Setup
// site_ID | site_Name | site_URL
$siteFound = $result[1];
$siteURL = $result[2];
?>
We have found the site that you are looking for. Here's the Name and URL:
<?php
echo $siteFound.': <a href="'.$siteURL'" target="_blank">'.$siteURL.'</a>' ;
?>

This should get you something like what you're looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.