Jump to content

Recommended Posts

I am doing a search engine for free for a Autism site.

I am having a problem with a php query returning an embedded link from a MySql db. The issue is it returns http://mysitename.com and then concatenates the link I had put in which is http://www.ada.com  

In the db Text field it is : <a href="http://www.ada.com" target="_blank">The Americans with Disabilities Act </a>was enacted in 1990 to establish the prohibition of discrimination....   

 

Results are the link goes to http://www.mysitename.com/"www.ada.com"  (Please notice the quotes as well). I don't know why it's putting in mysitename.com or why it's putting quotation marks around the real link or lastly why it's making my link a sub folder of mysitename.com. 

 

Pic of the results: results.png

 

Here is the code:

<?php

 

  // create short variable names

  $searchtype=$_POST['searchtype'];

  $searchterm=trim($_POST['searchterm']);

 

  

  if (!$searchtype || !$searchterm) {

echo '<p><strong>You have not entered search details.  Please go back and try again.</strong></p>';

exit;

  }

 

  if (!get_magic_quotes_gpc()){

    $searchtype = addslashes($searchtype);

    $searchterm = addslashes($searchterm);

  }

 

  @ $db = new mysqli("*","*","*","*");

  

  if (mysqli_connect_errno()) {

     echo 'Error: Could not connect to database.  Please try again later.';

     exit;

  }

 

  $query = "select * from acronymns where ".$searchtype." like '%".$searchterm."%' ORDER BY title ";

  $result = $db->query($query);

 

  $num_results = $result->num_rows;

 

  echo "<p>Number of records found: ".$num_results."</p>";

 

  for ($i=0; $i <$num_results; $i++) {

     $row = $result->fetch_assoc();

     echo "<p><strong>".($i+1).".  ";

     echo $row['acro'];

     echo  " - ";

     echo $row['title'];

     echo "</strong><br />";

     echo $row['desc'];

     echo "</p>";

  }

 

//  $result->free();

  $db->close();

 

?>

 

Thank you ahead of time.... this is really driving me nuts!

Are you absolutely, definitely, 100% sure that

In the db Text field it is : The Americans with Disabilities Act was enacted in 1990 to establish the prohibition of discrimination....

is exactly how it is in the database? I don't think it is, partly because I can't help but notice that the screenshot shows something different from what you said.

 

I think you have something more like

Maybe the output starts with "/" which is the domain name root directory because of the result using addslashes :)

Could you post out the echo of:

$query = "select * from acronymns where ".$searchtype." like '%".$searchterm."%' ORDER BY title ";

echo $query; exit;
Edited by jazzman1

 

Maybe the output starts with "/" which is the domain name root directory because of the result using addslashes :)

Could you post out the echo of:

$query = "select * from acronymns where ".$searchtype." like '%".$searchterm."%' ORDER BY title ";

echo $query; exit;

Here is the Echo:  select * from acronymns where title like '%ada%' ORDER BY title

You can't use smart quotes in HTML markup. Only straight quotes. Your browser is silently interpreting that HTML as

The  Americans with Disabilities Act  was enacted in 1990 to establish the prohibition ...
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.