Jump to content
MakeWebGames

searchdo.php


Newbie

Recommended Posts

Ok basicly iam having problems with this part of an search mod

file is called searchdo.php

 

<?php
include "globals.php";

$_POST['search'] = mysql_real_escape_string($_POST['search']);
$_POST['save'] = mysql_real_escape_string($_POST['save']);
$_POST['clear'] = mysql_real_escape_string($_POST['clear']);

if($_POST['search'])
{
$_POST['moneymin'] = abs(@intval($_POST['moneymin']));
$_POST['daysmax'] = mysql_real_escape_string($_POST['daysmax']);
$_POST['daysmin'] = mysql_real_escape_string($_POST['daysmin']);
$_POST['levelmin'] = abs(@intval($_POST['levelmin']));
$_POST['levelmax'] = abs(@intval($_POST['levelmax']));
$_POST['id'] = mysql_real_escape_string($_POST['id']);
$_POST['location'] = abs(@intval($_POST['location']));
$_POST['name'] = mysql_real_escape_string($_POST['name']);


$levelmin_clause="WHERE level >= {$_POST['levelmin']}";
$levelmax_clause=" AND level <= {$_POST['levelmax']}";
$id_clause=($_POST['id']) ? " AND userid LIKE('%{$_POST['id']}%')" : "";
$name_clause=($_POST['name']) ? " AND username LIKE('%{$_POST['name']}%')" : "";
$location_clause=($_POST['location']) ? " AND location LIKE('{$_POST['location']}')" : "";
$online_clause=($_POST['online']) ? " AND laston >= unix_timestamp()" : "";

$daysmin_clause=($_POST['daysmin']) ? " AND daysold >= {$_POST['daysmin']}" : "";
$daysmax_clause=($_POST['daysmax']) ? " AND daysold <= {$_POST['daysmax']}" : "";
$moneymin_clause=($_POST['moneymin']) ? " AND money > {$_POST['moneymin']}" : "";


$q=$db->query("SELECT * FROM users $levelmin_clause$levelmax_clause$id_clause$name_cl  ause$location_clause$online_clause$daysmin_clause$  daysmax_clause$moneymin_clause",$c);
print "
<table width='75%' cellspacing='1' class='table'><tr><th><h3>User Search Results</h2></th></tr></table>";


print"<table width='75%'><tr><td colspan='5'>";print mysql_num_rows($q)." Users found.

</td></tr><tr class='table'><th>User</th><th>Level</th><th>Money</th><th>Mug</th><th>Attack</th></tr>";
while($r=mysql_fetch_array($q))
{



print "<tr><td><a href='viewuser.php?u={$r['userid']}'>";



print" {$r['username']}";






print"</a></td><td>{$r['level']}</td><td>\${$r['money']}</td><td><a href='mug.php?ID={$r['>[Mug]</a></td><td><a href='attack.php?ID={$r['>[Attack]</a></td></tr>";
}
print "</table>";


}
else if($_POST['save'])
{


$_POST['moneymin'] = abs(@intval($_POST['moneymin']));
$_POST['daysmax'] = mysql_real_escape_string($_POST['daysmax']);
$_POST['daysmin'] = mysql_real_escape_string($_POST['daysmin']);
$_POST['levelmin'] = abs(@intval($_POST['levelmin']));
$_POST['levelmax'] = abs(@intval($_POST['levelmax']));
$_POST['id'] = mysql_real_escape_string($_POST['id']);
$_POST['location'] = abs(@intval($_POST['location']));
$_POST['name'] = mysql_real_escape_string($_POST['name']);


$levelmin_clause="WHERE level >= {$_POST['levelmin']}";
$levelmax_clause=" AND level <= {$_POST['levelmax']}";
$id_clause=($_POST['id']) ? " AND userid LIKE('%{$_POST['id']}%')" : "";
$name_clause=($_POST['name']) ? " AND username LIKE('%{$_POST['name']}%')" : "";
$location_clause=($_POST['location']) ? " AND location LIKE('{$_POST['location']}')" : "";

$online_clause=($_POST['online']) ? " AND laston >= unix_timestamp()" : "";

$daysmin_clause=($_POST['daysmin']) ? " AND daysold >= {$_POST['daysmin']}" : "";
$daysmax_clause=($_POST['daysmax']) ? " AND daysold <= {$_POST['daysmax']}" : "";
$moneymin_clause=($_POST['moneymin']) ? " AND money > {$_POST['moneymin']}" : "";


$q=$db->query("SELECT * FROM users $levelmin_clause$levelmax_clause$id_clause$name_cl  ause$location_clause$online_clause$daysmin_clause$  daysmax_clause$moneymin_clause",$c);
print "
<table width='75%' cellspacing='1' class='table'><tr><th><h3>Prisoner <span class='highlight'>Search</span> Results</h2></th></tr></table>";


print"<table width='75%'><tr><td colspan='5'>";print mysql_num_rows($q)." Users found.

</td></tr><tr colspan=1 class='table'><th>User</th><th>Level</th><th>Money</th><th>Mug</th><th>Attack</th></tr>";
while($r=mysql_fetch_array($q))
{


print "<tr><td><a href='viewuser.php?u={$r['userid']}'>";



print" {$r['username']}";






print"</a></td><td>{$r['level']}</td><td>\${$r['money']}</td><td><a href="http://mug.php?ID={$r[" target="_blank">[Mug]</a></td><td><a href="http://attack.php?ID={$r[" target="_blank">[Attack]</a></td></tr>";
}
print "</table>";


$sql = sprintf("SELECT * FROM <span class='highlight'>search</span> WHERE userid = %d ", $ir['userid']);

$q1 = mysql_query($sql);
if(mysql_num_rows($q1) > 0)
{

$updatesearch = sprintf
(
   "UPDATE `search` SET `id` = '%s', `moneymin` = '%d', `daysmax` = '%s', `daysmin` = '%s', `levelmin` = '%d', `levelmax` = '%d', `location` = '%d', name = '%s', `online` = '%s' WHERE `userid` = ('%u')",

   $_POST['id'],
   $_POST['moneymin'],
   $_POST['daysmax'], 
   $_POST['daysmin'] ,
   $_POST['levelmin'],
   $_POST['levelmax'],
   $_POST['location'],
   $_POST['name'],
   $_POST['online'],
   $ir['userid']


);


$db->query($updatesearch);
}

else
{
$insertsearch = sprintf
(
   "INSERT INTO `search` values ('' , '%u' , '%u' , '%s' , '%s' , '%u' , '%u' , '%s' , '%u' , '%s', '%s' )",

   $ir['userid'],
   $_POST['moneymin'],
   $_POST['daysmax'], 
   $_POST['daysmin'] ,
   $_POST['levelmin'],
   $_POST['levelmax'],
   $_POST['id'],
   $_POST['location'],
   $_POST['name'],
   $_POST['online']



);


$db->query($insertsearch);
}


}





else if($_POST['clear'])
{
$sql = sprintf("SELECT * FROM <span class='highlight'>search</span> WHERE userid = %d ", $ir['userid']);

$q1 = mysql_query($sql);
if(mysql_num_rows($q1) > 0)
{

$deletesearch = sprintf
(
   "DELETE FROM `search` WHERE `userid` = ('%u')",


   $ir['userid']


);


$db->query($deletesearch);
print"last <span class='highlight'>Search</span> has been Deleted";
}
else
{
print"You have no searches saved to delete... Stupid!!";
}
}
?>

 

 

im getting this error

Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/getty/public_html/searchdo.php on line 56

line 56

print"</a></td><td>{$r['level']}</td><td>\${$r['money']}</td><td><a href='mug.php?ID={$r['>[Mug]</a></td><td><a href='attack.php?ID={$r['>[Attack]</a></td></tr>";

 

any help would be great

Link to comment
Share on other sites

peace of cake

find

print"</a></td><td>{$r['level']}</td><td>\${$r['money']}</td><td><a href='mug.php?ID={$r['>[Mug]</a></td><td><a href='attack.php?ID={$r['>[Attack]</a></td></tr>";

and replace with

print"</a></td><td>{$r['level']}</td><td>\${$r['money']}</td><td><a href='mug.php?ID={$r['userid']}'>[Mug]</a></td><td><a href='attack.php?ID={$r['userid']}'>[Attack]</a></td></tr>";

hope it works

Edited by prototype
Link to comment
Share on other sites

Why is your script so convoluted? There's no need to apply a filter to every variable individually, you can use a loop.

 

 

Replace line 56 with:

 

print '</a></td>
  <td>' . $r['level'] . '</td>
  <td>' . $r['money'] . '</td>
  <td><a href="mug.php?ID=' . $r['userid'] . '">[Mug]</a></td>
  <td><a href="attack.php?ID= ' .$r['userid'] . '">[Attack]</a></td>


</tr>';
Edited by Spudinski
pfft... typo
Link to comment
Share on other sites

its not my script i got it off here but last comment was in 2010 and when i tried to reply there it wouldnt let me so i posted it here

ok spudinski your way gives me this error

Parse error: syntax error, unexpected T_STRING in /home/getty/public_html/searchdo.php on line 57

 

<td> . $r['level'] . '</td>

 

and prototype thanks :) worked fine

just got a error with the stupid sql file now :(

Link to comment
Share on other sites

QUERY ERROR:

Query was SELECT * FROM users WHERE level >= 1 AND level <= 500 ause AND location LIKE('1')$ daysmax_clause AND money > 1000

i got the mod from here but i couldnt reply there for some reason

http://makewebgames.io/showthread.php/33382-New-member-search?highlight=search

in the sql bit it doesnt say anything like ALTER TABLE users ADD etc

Edited by Newbie
posted wrong link fixed now
Link to comment
Share on other sites

i dunno illusions when i go onto my search.php everything works fine when i try to search say anyone with 1000 or more in london and hit search i get that error people on the other post said they added it to there game and it worked fine but that was like 2010

Link to comment
Share on other sites

The code highlighter is bugging up again, notice the variables within the query, $somcl ause

;)

alright after your comment i was confused so i went back and checked my searchdo.php and found what your talking about (well atleast i think i have)

 

$q=$db->query("SELECT * FROM users $levelmin_clause$levelmax_clause$id_clause$name_clause$location_clause$online_cl ause$daysmin_clause$  daysmax_clause$moneymin_clause",$c);

 

i changed to

$q=$db->query("SELECT * FROM users $levelmin_clause$levelmax_clause$id_clause$name_clause$location_clause$online_clause$daysmin_clause$ daysmax_clause$moneymin_clause",$c);

now i get this error lol

QUERY ERROR:

Query was SELECT * FROM users WHERE level >= 1 AND level <= 500 AND location LIKE('1') AND daysold >= 1$ daysmax_clause AND money > 50

 

that was me searching for users with 1 days or older and $50 or more

Edited by Newbie
Link to comment
Share on other sites

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.   Paste as plain text instead

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