Jump to content

Find name and add all together


andylord

Recommended Posts

will work i can see it now (( there was a extra comma before WHERE.

<?php

if (isset($_POST['Submit'])) {

$sql = "UPDATE $db_table SET Gold=Gold+".mysql_real_escape_string($_POST['Gold']).",
PvP=PvP+".mysql_real_escape_string($_POST['PvP']).",
Storage=Storage+".mysql_real_escape_string($_POST['Storage']).",
Other=Other+".mysql_real_escape_string($_POST['Other'])." 
WHERE Name='".mysql_real_escape_string($_POST['Name'])."'";

$res=mysql_query($sql)or die("update error".mysql_error());

echo '<h1>Thank you</h1>Your information has been entered into our database<br><br><img src="www.andys-cop-help.com"';
} else {

echo "ERROR: ".mysql_error();
}
?>

Link to comment
Share on other sites

try

$sql = "UPDATE $db_table SET 
Gold=Gold+".($_POST['Gold']+ 0).",
PvP=PvP+".($_POST['PvP'] + 0).",
Storage=Storage+".($_POST['Storage'] + 0).",
Other=Other+".($_POST['Other'] + 0)." 
WHERE Name='".mysql_real_escape_string($_POST['Name'])."'";

remove , before WHERE

 

Ok it seems this works but when i hit enter it doesnt submit to the mysql

 

 

Before this i have the connect which is working

so must be something below as it was working with the very first code ...

 

<?php

if (isset($_POST['Submit'])) {

$sql = "UPDATE $db_table SET
Gold=Gold+".($_POST['Gold']+ 0).",
PvP=PvP+".($_POST['PvP'] + 0).",
Storage=Storage+".($_POST['Storage'] + 0).",
Other=Other+".($_POST['Other'] + 0)."
WHERE Name='".mysql_real_escape_string($_POST['Name'])."'";
$res=mysql_query($sql)or die("update error".mysql_error());

echo '<h1>Thank you</h1>Your information has been entered into our database<br><br><img src="www.andys-cop-help.com"';
} else {

echo "ERROR: ".mysql_error();
}
?>

<h1> </h1>
<hr>

 <form method="post" action="">
               <p>Legend: </p>
               <p>50G = 1Point<br />
                 PvP = Winner of competitions only at the moment<br />
                 Storage = Giving away valuable items, Helping others etc decided at the time by an officer. 5,10,15,20-100 in this region.<br />
                 Other = Decided by officer same as storage. </p>
               <p> </p>
               <p>Name:<br>
                 <textarea name="Name"></textarea>
                 <br />
                 <br>
                 Gold: <br>
                 <input type="text" name="Gold">
                 <br>
                 <br>
                 PvP: <br>
                 <input type="text" name="PvP">
                 <br>
                 <br>
                 Storage: <br>
                 <input type="text" name="Storage">
                 <br>
                 <br>
                 Other: <br>
                 <textarea name="Other"></textarea>
               </p>
               <p>
                 <input type="submit" name="Submit" value="Submit">
                 </p>
               <p> </p>
               <p> </p>
               <p> </p>
 </form>

The Phpmyadmin table is like this:

 

Field Type Collation Attributes Null Default Extra Action

Name text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext

Gold text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext

PvP text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext

Storage text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext

Other text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext

Total text latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext

Link to comment
Share on other sites

well, if the field values like 'Gold', etc are always going to be numbers, dont the columns have to be type 'int' or something comperable to be doing the additive operation in the SQL statement?

 

For something like this, what I would do is comment out the actual SQL statement in your code and just echo out what the text of the statement is.  Throw that into SQL and see if it throws any errors.

If it doesn't throw any errors and the data is properly updated, perhaps you still have a problem with your PHP.  make sure you have error reporting on and set to E_ALL and run it again to see if anything pops up

Link to comment
Share on other sites

ok so i did this:

 

 

<?php

 

if (isset($_POST['Submit'])) {

$sql = "UPDATE $db_table Points

Gold=Gold+".($_POST['Gold']+ 0).",

PvP=PvP+".($_POST['PvP'] + 0).",

Storage=Storage+".($_POST['Storage'] + 0).",

Other=Other+".($_POST['Other'] + 0)."

WHERE Name='".mysql_real_escape_string($_POST['Name'])."'";

$res=mysql_query($sql)or die("update error".mysql_error());

 

echo '<h1>Thank you</h1>Your information has been entered into our database<br><br><img src="www.andys-cop-help.com"';

} else {

 

echo "ERROR: here area 1 ".mysql_error();

}

?>

 

and the page showed ERROR: here area 1

 

so it must be something here but cannot see anything can you guys help me out again please thanks

 

when i click submit it shows this also

 

update errorYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Gold=Gold+0, PvP=PvP+0, Storage=Storage+0, Other=Other+1 WHERE Name='Testname'' at line 2

 

And i changed the fields to int for Gold, PvP, Storage, Other

Link to comment
Share on other sites

your if / else makes no sense. 

 

basically, you said if the user pressed submit, run the insert statement

otherwise, print the error message.

This has nothing to do with whether or not there was an actual error on the page

 

and you still didn't follow my suggestion of echoing the SQL statement and manually putting it through SQL to troubleshoot it.

Link to comment
Share on other sites

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.