Jump to content

Search for a variable in mysql


blogit

Recommended Posts

I'm having trouble with a script that is pretty basic but my coding is that great so far i have it getting the current domain and putting it into a variable which is simple enough, I then want it to run a search on a table in a database and if the current domain is there to echo it out. The mysql query im using is below if anyone can help with the rest i'd really appreciate it.

 

<?php
include 'config.php';
include 'opendb.php';

$pageUR1  = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
$curdomain  = str_replace("www.", "", $pageUR1);

$query  = "SELECT page_url FROM page LIKE '%$curdomain%'";

 

Link to comment
https://forums.phpfreaks.com/topic/106867-search-for-a-variable-in-mysql/
Share on other sites

Try

 

<?php
include 'config.php';
include 'opendb.php';

$pageUR1  = ereg_replace("/(.+)", "", $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
$curdomain  = str_replace("www.", "", $pageUR1);

$query  = "SELECT COUNT(*) FROM page WHERE page_url='$curdomain'";
$result = mysql_query($query)or die(mysql_error());
$count = mysql_result($result, 0);

if ($count > 0)
   echo $curdomain;
else
   echo "Domain not in database";

?>

Archived

This topic is now archived and is closed to further replies.

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