Having a problem running a query

Forum
Last Post
Threads / Messages

!Alive

Member
Member
Joined
Feb 20, 2012
Messages
39
Points
0
Mysidian Dollar
0
So what I'm trying to accomplish is every time the page changes/reloaded check to see if the user has won a random, mystery prize. Right now I have got the random prize page working and I already have the piece of code that randomly decides if the user wins something.
My problem is that it doesn't run my query to update the info in the table. I think my problem may be where I have put the code, which I currently have located in the functions.php.

Any help would be greatly appreciated.
Thank you much in advance.
 
umm the mysql update query wont work? Well I've had problems like this at times but theres really an easy way to debug. The mysql query string may have a typo in it, or the variables used to locate or update the database contain wrong information. To debug, lets consider the example below:

PHP:
runquery("UPDATE {$prefix}adoptables_conditions SET promocode='{$code}' WHERE type='{$type}'");

The query string is enclosed in the function runquery. The variable $code is used to update database info, while the other variable $type is used to locate the specific row in a table. You can debug by outputting values inside the variables $code and $type to the screen and see if they contain the correct information. If so, you've apparently made a typo with the query string. Otherwise, chances are you've incorrectly assigned values to $code or $type.
 
PHP:
$number=rand(1,2);
	if ($number == 2){
	runquery("UPDATE ".$GLOBALS['prefix']."users SET explore='1' WHERE username".$GLOBALS['loggedinname']);
	
	$query = "SELECT * FROM ".$GLOBALS['prefix']."users WHERE username".$GLOBALS['loggedinname'];
	$result = mysql_query($query);
	$explore=@mysql_result($result,0,"explore");
	echo "$explore";

	return $explore;
	if ($explore == 1){
	header( 'Location: browseprize.php' ) ;
		}
		}

That's my code I'm running. I don't think I have any sytax errors, but I'm still new to this so I could be wrong.
 
umm your query is wrong, try this:

PHP:
runquery("UPDATE {$GLOBALS['prefix']}users SET explore='1' WHERE username = '{$loggedinname}'"); 
$query = "SELECT * FROM {$GLOBALS['prefix']}users WHERE username = '{$loggedinname}'";
 
You are very welcome, glad it works out for you. Another quick note is that at times it does not work because you are using mysql's reserved word. I ran into this problem once, in which the field name 'usage' is a reserved word and thus cannot be used. Because of this I could not manage to create the table prefix.items_functions. I changed it to 'intent' instead and the problem is all gone.
 
You are very welcome, glad it works out for you. Another quick note is that at times it does not work because you are using mysql's reserved word. I ran into this problem once, in which the field name 'usage' is a reserved word and thus cannot be used. Because of this I could not manage to create the table prefix.items_functions. I changed it to 'intent' instead and the problem is all gone.

This might be slightly out of topic, but it's also worth noting that you can still use a reserved keyword if you enclose it with backticks.
 
@ Fadillzzz: Yeah you are right, I actually tried that before but it still gave me an error. Turned out that I was using single quote instead of backticks, oh my...
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top