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

?>

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.