redarrow Posted March 10, 2009 Share Posted March 10, 2009 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148780-find-name-and-add-all-together/page/2/#findComment-781538 Share on other sites More sharing options...
andylord Posted March 10, 2009 Author Share Posted March 10, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/148780-find-name-and-add-all-together/page/2/#findComment-781544 Share on other sites More sharing options...
redarrow Posted March 10, 2009 Share Posted March 10, 2009 there nothing wrong with my code or op code for god sake...... Quote Link to comment https://forums.phpfreaks.com/topic/148780-find-name-and-add-all-together/page/2/#findComment-781546 Share on other sites More sharing options...
lonewolf217 Posted March 10, 2009 Share Posted March 10, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/148780-find-name-and-add-all-together/page/2/#findComment-781549 Share on other sites More sharing options...
andylord Posted March 10, 2009 Author Share Posted March 10, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/148780-find-name-and-add-all-together/page/2/#findComment-781560 Share on other sites More sharing options...
lonewolf217 Posted March 10, 2009 Share Posted March 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/148780-find-name-and-add-all-together/page/2/#findComment-781563 Share on other sites More sharing options...
sasa Posted March 11, 2009 Share Posted March 11, 2009 where is SET command in your sql? Quote Link to comment https://forums.phpfreaks.com/topic/148780-find-name-and-add-all-together/page/2/#findComment-781780 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.