Jump to content

[SOLVED] Beta link sharing site, problem with MySQL table searching


exutable

Recommended Posts

Hey I am having trouble searching through my database where category=$category, it tells me that result isn't a valid MySQL argument but it looks legit to me.

 

http://www.daneshea.com/shareabyte

Click on movies and you will find the error on line 71

 

 

I know the code is really unorganized sorry.

 

 

 

<?
session_start();
?>
<link rel="stylesheet" type="text/css" href="/links.css">
<?
include("connect.php");
include("functions.php");

if(!$_REQUEST['offset']) {
        $offset = 0;
        }
else {
        $offset = $_REQUEST['offset'];
     }
$range = 20;
$searchby = $_REQUEST["searchby"];
$order = $_REQUEST["order"];
$name = $_REQUEST['name'];
$link = $_REQUEST['link'];
$category = $_REQUEST['category'];
$categoryarray = array("Movies", "Games", "Porn", "Videos");
$amount = count($categoryarray);


$http = strchr($link, "http://");
$com = strchr($link, ".com");
$net = strchr($link, ".net");
$org = strchr($link, ".org");




if($name) {
if($http and ($com or $net or $org)) {

post($name, $link);

}
elseif(!$http and ($com or $net or $org)) {
        $link = "http://$link";
        post($name, $link);

}
else {
        echo "<p align=\"center\"><font color=\"red\">Invalid Link!</font></p>";
      
}
}
if($searchby) {
        $amount = mysql_result(mysql_query("select COUNT(*) from rapidshare where (name LIKE '%$searchby%' OR link LIKE '%$searchby%')"),0);
        $result = "select name, link, date_format(time, '%c/%e/%Y') as thetime from rapidshare where name LIKE '%$searchby%' order by name $order limit $offset,$range";
     
if($offset >= $range) {
        $prev = $offset-$range;
        $prevlink = "<span class=\"class4\"><a href=\"index.php?searchby=$searchby&order=$order&offset=$prev\">Prev</a></span>";
        }
else {
        $prevlink = "Prev";
        }
if($amount > $range) {
        $next = $offset+$range;
        $nextlink = "<span class=\"class4\"><a href=\"index.php?searchby=$searchby&order=$order&offset=$next\">Next</a></span>";
        }
else {
        $nextlink = "Next";
        }
}

elseif($category) {
$amount = mysql_result(mysql_query("select COUNT(*) from rapidshare where category=$category"),0);
        $result = "select name, link, date_format(time, '%c/%e/%Y') as thetime from rapidshare where category=$category order by name $order limit $offset,$range";
if($offset >= $range) {
        $prev = $offset-$range;
        $prevlink = "<span class=\"class4\"><a href=\"index.php?category=$category&order=$order&offset=$prev\">Prev</a></span>";
        }

else {
        $prevlink = "Prev";
        }

if($amount > $range) {
        $next = $offset+$range;
        $nextlink = "<span class=\"class4\"><a href=\"index.php?category=$category&order=$order&offset=$next\">Next</a></span>";
        }

else {
        $nextlink = "Next";
        }
}

elseif($searchby && $category) {
        
$amount = mysql_result(mysql_query("select COUNT(*) from rapidshare where (name LIKE '%$searchby%' OR link LIKE '%$searchby%') and category = '$category'"),0);
        $result = "select name, link, date_format(time, '%c/%e/%Y') as thetime from rapidshare where name LIKE '%$searchby%' and category = '$category' order by time desc limit $offset,$range";

if($offset >= $range) {
        
$prev = $offset-$range;
        $prevlink = "<span class=\"class4\"><a href=\"index.php?category=$category&searchby=$searchby&order=asc&offset=$prev\">Prev</a></span>";
        }

else {
        $prevlink = "Prev";
        }

if($amount > $offset+$range) {
        
$next = $offset+$range;
        $nextlink = "<span class=\"class4\"><a href=\"index.php?category=$category&searchby=$searchby&order=asc&offset=$next\">Next</a></span>";
        }

else {
        $nextlink = "Next";
        }
}


$nav = "$prevlink | $nextlink";

$query = mysql_query($result);




echo "<body><table cellpadding=2 border=0 align=\"center\" width=\"100\">
<tr><td colspan=\"2\"><span class=\"class2\"><a href=\"post.php\">Post Rapidshare Link</a> | <a href=\"index.php\">Show All</a>"; if($admin == "3") { echo" | <a href=\"/linklogin.php\">Administration</a></span>"; } echo "</td></tr>
<tr><td colspan=\"2\"><h1>Search ShareAbyte</h1></td></tr>
<tr><td colspan=\"2\">Search for links here and they will be displayed below.</td></tr>
<form action=\"index.php\" method=\"post\">
<tr><td>Search:<br><input type=\"text\" name=\"searchby\" style=\"border: 1px solid #000; background-color: #E9EAFF;\"></td><td>Order:<br><select name=\"order\" style=\"border: 1px solid #000; background-color: #E9EAFF;\"><option value=\"asc\">Ascending [A-Z]</option><option value=\"desc\">Descending [Z-A]</option></select></td></tr>
<tr><td colspan=\"2\"><input type=\"submit\" value=\"Search\"></td></tr>
<tr><td colspan=\"2\"><hr></td></tr>
</form>";

if($amount == 0) {
        echo "<tr><td align=\"center\">No result from your search.</td></tr>";
        die();
        }
if($category || $searchby) {
$i = 0;
print_r($query);
     while($row = mysql_fetch_array($query)) {
     $i++; // same thing as you had $i++ is the exact equiv of $i = $i+1;
     extract($row);
           echo "<td><span class=\"class4\"><a href=\"$link\" target=\"_blank\">$name</a></span></td>";
     if($i % 2 == 0) {echo "</tr><tr>"; }
}
}

else {
$a = count($categoryarray);
for ($i = 0; $i<$a; $i++) {

echo "<td><span class=\"class4\"><a href=\"index.php?category=$categoryarray[$i]\" target=\"_blank\">$categoryarray[$i]</a></span></td>";
     if($i % 2 == 0) {echo "</tr><tr>"; }
}
die();
}

echo "<br><tr><td colspan=\"2\"><hr></td></tr>";
echo "<tr><td colspan=\"2\">$nav</td></tr>";
echo "<tr><td colspan=\"2\"><hr></td></tr></table></body>";

?>

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.