|
-
Sep 27th, 2006, 09:53 PM
#1
Thread Starter
Addicted Member
Problem with Updating Values
For some reason I cannot get a value changed in a database with a script. I am designing an MMORPG using PHP for use in the browser, and I need to make a server-status script.
But for some reason I cannot get the value to update, here is the code (excluding database username, password, etc).
PHP Code:
//The MySQL Variables
$server = "---";
$username = "---";
$password = "---";
$database = "tfdo_e";
$username1 = $_SESSION['UserName'];
$password1 = $_SESSION['PassWord'];
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
//Send Query To Set Players + 1
$query="SELECT Kingdom FROM tfdo_e_users WHERE Username=$username1 AND Password=$password1";
$kingdom=mysql_query($query);
if ($kingdom == "FOD")
{
$playerkingdom = "Forest of Draagul";
}
if ($kingdom == "VOS")
{
$playerkingdom = "Valley of Snakes";
}
if ($kingdom == "CON")
{
$playerkingdom = "City of Nahana";
}
$query="SELECT Server FROM tfdo_e_server WHERE Server=$playerkingdom";
$number=mysql_query($query);
$finalnumber=$number+1;
$query="UPDATE tfdo_e_server SET Players='$finalnumber' WHERE Server='$playerkingdom'";
mysql_query($query);
}
else
{
js_redirect_notloggedin();
}
function js_redirect_notloggedin($url="notloggedin.php", $seconds=0.1) {
echo "<script language=\"JavaScript\">\n";
echo "<!-- hide from old browser\n\n";
echo "function redirect() {\n";
echo "window.location = \"" . $url . "\";\n";
echo "}\n\n";
echo "timer = setTimeout('redirect()', '" . ($seconds*100) . "');\n\n";
echo "-->\n";
echo "</script>\n";
return true;
}
-
Sep 27th, 2006, 10:04 PM
#2
Re: Problem with Updating Values
What are the echoed values of $finalnumber and $playerkingdom just before you update?
-
Sep 27th, 2006, 10:06 PM
#3
Thread Starter
Addicted Member
Re: Problem with Updating Values
What do you mean "What are the echoed values?", there are no echoed values, this is PHP 5 meaning that I can just store variables at runtime, if that is what you are asking.
-
Sep 27th, 2006, 11:07 PM
#4
Re: Problem with Updating Values
hmm, couldn't you -always- store variables at runtime?
just before I go into anything, why don't you use elseif() statements instead of 3 seperate IF statements when defining $playerkingdom? Just curious, and thought it might help a bit.. although it has nothing to do with your problem!
Looking at your code and thinking back to past experiences, the only problem I can see is that you're using $query twice and one is used in a query to define a variable. You could always try changing the second variable's name to see if the problem persists, and I just bring this up because from what I've experienced if you define a query to a variable, the query variable becomes 'reserved,' or something. It was a while ago, but from then on I just have individual names for each query. Honestly, it sounds like a dumb reason for it to not work, but it happens, I suppose. Or, it could have nothing to do with that.
I looked over your stuff a few times and without an error message it seems your SQL statements are fine as are most other things.. so hey, try it out. You could always make a $query[] variable and then do something like:
PHP Code:
$query['kingdom'] = "select blahblah from blahblah where kingdom=blahblah";
$blahblah = mysql_query($query);
$query['update'] = "update blahblah set blahblah=blahblah where blahblah=blahblah";
mysql_query($query['update']);
Let me know.
-
Sep 28th, 2006, 06:24 PM
#5
Thread Starter
Addicted Member
Re: Problem with Updating Values
Thanks, I will try that when I get a chance, see, all the code that I am writing is pretty much from memory, so I am seseptible to mistakes like that .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|