Feelay 0 Report post Posted February 19, 2008 Hey!I am trying to do a "Admin give EXP script".But I can't make it work.The value is not updating, but the update query is correct.( I think:P)I think the fault is here: $expcomp=$givexpp['exp'] += $givexp; The $givexp is the variable for the amount of Xp the admin wants to give.the $givexpp is the variable for the user info (in this case, the experince he already have).The datatype for the XP in the database is INT. So I have no idea if it can take data from a normal textfield.If you need to see all the code, here you go:<?phpsession_start();include "database.php";$givexpto= mysql_real_escape_string($_POST['givexpto']);$givexp= mysql_real_escape_string($_POST['givexp']);$queryxp =("SELECT * FROM characters WHERE user='$givexpto'")or die(mysql_error()); if(mysql_num_rows(mysql_query($queryxp)) == 1) { $givexpp = mysql_fetch_assoc(mysql_query($queryxp)); }else{ die("User Don't Excist. Please Go Back And Try Again");}$expcomp=$givexpp['exp'] += $givexp;mysql_query("UPDATE characters SET exp='$expcomp' WHERE user='$givexpto'");header("location:index.php");?> Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted February 20, 2008 Hey!I am trying to do a "Admin give EXP script".But I can't make it work.The value is not updating, but the update query is correct.( I think:P)I think the fault is here: $expcomp=$givexpp['exp'] += $givexp; The $givexp is the variable for the amount of Xp the admin wants to give.the $givexpp is the variable for the user info (in this case, the experince he already have).The datatype for the XP in the database is INT. So I have no idea if it can take data from a normal textfield.If you need to see all the code, here you go:<?phpsession_start();include "database.php";$givexpto= mysql_real_escape_string($_POST['givexpto']);$givexp= mysql_real_escape_string($_POST['givexp']);$queryxp =("SELECT * FROM characters WHERE user='$givexpto'")or die(mysql_error()); if(mysql_num_rows(mysql_query($queryxp)) == 1) { $givexpp = mysql_fetch_assoc(mysql_query($queryxp)); }else{ die("User Don't Excist. Please Go Back And Try Again");}$expcomp=$givexpp['exp'] += $givexp;mysql_query("UPDATE characters SET exp='$expcomp' WHERE user='$givexpto'");header("location:index.php");?> Always debug your variables to verify if its values are the expected ones, you can do it simply by echoing it.Try this:<?phpsession_start();include "database.php";$givexpto= mysql_real_escape_string($_POST['givexpto']);$givexp= (int) mysql_real_escape_string($_POST['givexp']);echo $givexp;$queryxp="SELECT * FROM characters WHERE user='$givexpto'"; if(mysql_num_rows(mysql_query($queryxp))>0) { $givexpp = mysql_fetch_assoc(mysql_query($queryxp));} else { die("User Don't Excist. Please Go Back And Try Again"); }$expcomp=$givexpp['exp'] + $givexp;mysql_query("UPDATE characters SET exp=$expcomp WHERE user='$givexpto'");header("location:index.php");exit;?>Best regards, Share this post Link to post Share on other sites
Feelay 0 Report post Posted February 20, 2008 "(int)" don't work. I've tryed that before, and now I tryed it with your code.It is still showing value "0" where "$givexp" is. Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted March 1, 2008 Which method do you use on your form to submit your data??? If you are using the GET method simply replace the $_POST's variables with $_GET's like this: <?php$givexpto= mysql_real_escape_string($_GET['givexpto']);$givexp= (int) mysql_real_escape_string($_GET['givexp']);?>And, I'm not pretty sure about this but just in case, try this code instead: <?php$givexpto= mysql_real_escape_string($_POST['givexpto']);$givexp= (int) $_POST['givexp'];/* USE THIS IF YOU USE THE GET METHOD $givexpto= mysql_real_escape_string($_GET['givexpto']);$givexp= (int) $_GET['givexp'];*/?>Also, take a look to these topics: Php String To Int Typecasting Checking To See If Something Is Not An IntegerBest regards, Share this post Link to post Share on other sites