kernelgpf Posted October 13, 2007 Share Posted October 13, 2007 Here's my entire script- it's worked previously, and is suddenly not working.. no errors, nothing being printed. That's the problem. <?php include "header.php"; print "Searching usernames is searching all player's BASIC names, not their display names.<p>"; if($_GET['action'] == "search"){ $name=$_POST['username']; $idnumber=$_POST['idnumber']; $acctkind=$_POST['acctkind']; $onstatus=$_POST['onstatus']; if($acctkind == "Premium"){ $acctkind=1; } if($acctkind == "normal"){ $acctkind=0; } if($acctkind == "Doesn\'t Matter"){ $acctkind=""; } if($onstatus == "Doesn\'t Matter"){ $query=mysql_query("select displayname,id from users where basicname LIKE '$name%' AND id LIKE '$idnumber%' AND acctkind LIKE '$acctkind%' ORDER BY id ASC")or die(mysql_error()); } if($onstatus == "Online"){ $query=mysql_query("select displayname,id from users where basicname LIKE '$name%' AND id LIKE '$idnumber%' AND acctkind LIKE '$acctkind%' AND lli > (NOW() - INTERVAL 2 MINUTE)")or die(mysql_error()); } if($onstatus == "Offline"){ $query=mysql_query("select displayname,id from users where basicname LIKE '$name%' AND id LIKE '$idnumber%' AND acctkind LIKE '$acctkind%' AND lli < (NOW() - INTERVAL 2 MINUTE)")or die(mysql_error()); } $num=mysql_num_rows($query); if($num == "0"){ print "No matches to your search query."; include "footer.php"; exit; } while($thing=mysql_fetch_array($query)){ print "<a href='userprofiles.php?id=$thing[id]'>$thing[displayname]</a><br>"; } include "footer.php"; exit; } ?> <form method=post action=searchusers.php?action=search> Username: <input type=text name=username><br> Player ID#: <input type=text name=idnumber><br> Account Type: <select name=acctkind> <option>Doesn't Matter</option> <option>Premium</option> <option>normal</option></select><br> Online/Offline: <select name=onstatus> <option>Doesn't Matter</option> <option>Online</option> <option>Offline</option> </select><br> <input type=submit name=submit value='Search Users'> </form> <?php include "footer.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/ Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 try mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368303 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 Tried- didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368305 Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 try <?php print '<a href=userprofiles.php?id='.$thing[id].'>'.$thing[displayname].'</a><br>';?> Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368307 Share on other sites More sharing options...
pocobueno1388 Posted October 13, 2007 Share Posted October 13, 2007 Have you tried to echo some text between the if ($_GET['action'] == "search") brackets? Maybe your script isn't even reaching that part of the code when you press search. Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368308 Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 no poc its bad dynamic linkcode Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368309 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 Doesn't work either, darkfreaks. And Colin- it's getting there, I've printed some stuff out. Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368311 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 As an extra helpful note, it's printing out "<a href='userprofiles.php?id='></a>".. no variables. =[ Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368313 Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 <?php print '<a href=userprofiles.php?id='. $thing['id'] .'>'. $thing['displayname'] .'</a><br>';?> Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368319 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 Caused a parse error. Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368321 Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 <?php print '<a href=userprofiles.php?id='. $thing['id'] .'>'. $thing['displayname'] .'</a><br>';?> Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368322 Share on other sites More sharing options...
pocobueno1388 Posted October 13, 2007 Share Posted October 13, 2007 Okay, try this: EDIT Don't try it yet...hold on. EDIT AGAIN Okay, try it now. <?php include "header.php"; print "Searching usernames is searching all player's BASIC names, not their display names.<p>"; if ($_GET['action'] == "search") { $name=$_POST['username']; $idnumber=$_POST['idnumber']; $acctkind=$_POST['acctkind']; $onstatus=$_POST['onstatus']; if ($acctkind == "Premium") $acctkind=1; if ($acctkind == "normal") $acctkind=0; if ($acctkind == "Doesn\'t Matter") $acctkind=""; if ($onstatus == "Doesn\'t Matter") $query= "select displayname,id from users where basicname LIKE '%$name%' AND id LIKE '%$idnumber%' AND acctkind LIKE '%$acctkind%' ORDER BY id ASC"; else if ($onstatus == "Online") $query= "select displayname,id from users where basicname LIKE '%$name%' AND id LIKE '%$idnumber%' AND acctkind LIKE '%$acctkind%' AND lli > (NOW() - INTERVAL 2 MINUTE)"; else if ($onstatus == "Offline") $query= "select displayname,id from users where basicname LIKE '%$name%' AND id LIKE '%$idnumber%' AND acctkind LIKE '%$acctkind%' AND lli < (NOW() - INTERVAL 2 MINUTE)"; $result = mysql_query($query)or die(mysql_error()); $num = mysql_num_rows($result); if ($num == "0") { print "No matches to your search query."; include "footer.php"; exit; } while ($thing = mysql_fetch_assoc($result)) { print "<a href='userprofiles.php?id={$thing['id']}'>{$thing['displayname']}</a><br>"; } include "footer.php"; exit; } ?> <form method="post" action="searchusers.php?action=search"> Username: <input type="text" name="username"><br> Player ID#: <input type="text" name="idnumber"><br> Account Type: <select name="acctkind"> <option>Doesn't Matter</option> <option>Premium</option> <option>normal</option></select><br> Online/Offline: <select name="onstatus"> <option>Doesn't Matter</option> <option>Online</option> <option>Offline</option> </select><br> <input type="submit" name="submit" value="Search Users"> </form> <?php include "footer.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368325 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 Parse error, line 22... the first couple queries you have just the query's guts in the var. $query, but in others, you have the guts and the "mysql_query("");".. which is meant to be? Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368329 Share on other sites More sharing options...
pocobueno1388 Posted October 13, 2007 Share Posted October 13, 2007 You must have missed my edit? Try it again, it's updated. Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368330 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 -nods- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368332 Share on other sites More sharing options...
pocobueno1388 Posted October 13, 2007 Share Posted October 13, 2007 Okay, change this line $result = mysql_query($query)or die(mysql_error()); To $result = mysql_query($query)or die(mysql_error().$query); Then copy and paste what it prints. In all your queries you had LIKE '$var%' I looked up the syntax for LIKE and they had a percent sign on both sides of the variable...so I changed that. You might be able to do it with the one as well...you might want to change it to one just to make sure, and see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368337 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 It works that way too. Two percent signs makes it so it searches all user IDs with a "1" in them, while my way only brings up account IDs that START with 1. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1Resource id #6 Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368341 Share on other sites More sharing options...
pocobueno1388 Posted October 13, 2007 Share Posted October 13, 2007 It should have printed out the darn query... Try putting this: echo $query.'<p>'; $result = mysql_query($query)or die(mysql_error().' ERROR: '.$query); Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368350 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1ERROR:Resource id #6 What the heck is "resource ID #6"? O_o Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368355 Share on other sites More sharing options...
pocobueno1388 Posted October 13, 2007 Share Posted October 13, 2007 I wonder why the echo $query.'<p>'; didn't show up 0_o I'm sure it has something to do with all those LIKE statements in there. I would post your query and error in the MySQL forum. Fenway, Barand or some other super guru will come by and probably correct it in no time. Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368359 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 I didn't paste that part, sorry. I don't have time.. I'll keep messing with it. Thanks for the help anywho.. =S Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368364 Share on other sites More sharing options...
kernelgpf Posted October 13, 2007 Author Share Posted October 13, 2007 I figured it out- when I switched servers, the $onstatus variable didn't have the backslash in it. =S Thanks for your help though. =] Quote Link to comment https://forums.phpfreaks.com/topic/73029-solved-strange-problem-cant-get-mysql_fetch_array-to-work/#findComment-368649 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.