SirChick Posted August 15, 2007 Share Posted August 15, 2007 $FindEXP = ("SELECT * FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'"); $AddEXP = ("UPDATE userregistration WHERE CrimeExp * +12"); Basically what its doing here is selecting the row of the userID .... the UserID is in the session and then it updates the field "crimeexp" by adding 12. Not sure why it doesnt work though, is it cos i have seperated them ? Quote Link to comment https://forums.phpfreaks.com/topic/65115-solved-is-this-correct/ Share on other sites More sharing options...
php_tom Posted August 15, 2007 Share Posted August 15, 2007 $FindEXP = ("SELECT * FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'"); $AddEXP = ("UPDATE userregistration WHERE CrimeExp * +12"); if you're doing it in PHP i think you want $FindEXP = mysql_query("SELECT * FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'"); $AddEXP = mysql_query("UPDATE userregistration WHERE CrimeExp * +12"); Also, what kind of condition is WHERE CrimeExp * +12? I've never seen anything like that before, maybe check your SQL syntax on that. Quote Link to comment https://forums.phpfreaks.com/topic/65115-solved-is-this-correct/#findComment-324974 Share on other sites More sharing options...
SirChick Posted August 15, 2007 Author Share Posted August 15, 2007 well it didnt give me a syntax error lol basically is physically adds 12 to the integer in the field "crimeexp" like: where field name "crimeexp" has *wildcard (Any value) + 12 (add 12 to the value). basically when the script runs it adds 12 to the field lol pretty straight forward. i didnt see the need for doing like $add = 12 then $add + $Addexp = $NewEXp then update $newexp it seemed over the top. ill try: $FindEXP = mysql_query("SELECT * FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'"); $AddEXP = mysql_query("UPDATE userregistration WHERE CrimeExp * +12"); EDIT: Still doesnt add the 12 to it Quote Link to comment https://forums.phpfreaks.com/topic/65115-solved-is-this-correct/#findComment-324983 Share on other sites More sharing options...
akitchin Posted August 15, 2007 Share Posted August 15, 2007 if you're trying to restrict adding 12 to ONLY the crimeexp of the user whose id is $_SESSION['Current_User'], you can do the following: $query = "UPDATE userregistration SET CrimeExp=CrimeExp+12 WHERE UserID='{$_SESSION['Current_User']}'"; otherwise, to just add 12 to EVERYONE's crimeexp, you could do: $query = "UPDATE userregistration SET CrimeExp=CrimeExp+12"; Quote Link to comment https://forums.phpfreaks.com/topic/65115-solved-is-this-correct/#findComment-324992 Share on other sites More sharing options...
SirChick Posted August 15, 2007 Author Share Posted August 15, 2007 still doesnt work for some reason $query = "UPDATE userregistration SET CrimeExp=CrimeExp+12 WHERE UserID='{$_SESSION['Current_User']}'"; this is the one im using Quote Link to comment https://forums.phpfreaks.com/topic/65115-solved-is-this-correct/#findComment-324994 Share on other sites More sharing options...
SirChick Posted August 15, 2007 Author Share Posted August 15, 2007 this is what i got at the moment: include("globalscriptforconnect.php"); // Start up the session session_start(); if (!isset($_SESSION['Current_User']) || !$_SESSION['Current_User']) { die('You must be logged in to view this page'); } //error handle if (!mysql_select_db("civilian")) { echo "Unable to select Civilain: " . mysql_error(); exit; } // Get the user's info from the database by putting // the user id stored in the session into the WHERE clause $GetUserID = mysql_query("SELECT * FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'"); // Fetch the row from the database if (!($row = mysql_fetch_assoc($GetUserID))) { echo "User not found!"; exit; } $addcrimeexp = "UPDATE userregistration SET CrimeExp=CrimeExp+12 WHERE UserID='{$_SESSION['Current_User']}'"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/65115-solved-is-this-correct/#findComment-325013 Share on other sites More sharing options...
akitchin Posted August 15, 2007 Share Posted August 15, 2007 if you're not actually using any of the info in that SELECT query, you don't need it at all. you can do the following: // update the user's crimeexp to 12 more than what it was $addcrimeexp = "UPDATE userregistration SET CrimeExp=CrimeExp+12 WHERE UserID='{$_SESSION['Current_User']}'"; $result = mysql_query($addcrimeexp) or die(mysql_error()); if (mysql_affected_rows() == 0) { die('Update failed'); } you don't need the select - you can put this stuff right below the select_db section. Quote Link to comment https://forums.phpfreaks.com/topic/65115-solved-is-this-correct/#findComment-325016 Share on other sites More sharing options...
SirChick Posted August 15, 2007 Author Share Posted August 15, 2007 oh ok. its working thankyou ! Quote Link to comment https://forums.phpfreaks.com/topic/65115-solved-is-this-correct/#findComment-325030 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.