Jump to content

Recommended Posts

$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 ?

Link to comment
https://forums.phpfreaks.com/topic/65115-solved-is-this-correct/
Share on other sites

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

 

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 :(

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";

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']}'";
?>

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.