|
|
|
|
![]() ![]() |
Feb 19 2008, 05:53 PM
Post
#1
|
|
|
Kinda N00B Group: Members Posts: 230 Joined: 13-January 08 From: Sweden Member No.: 27,579 |
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: CODE $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: CODE <?php
session_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"); ?> |
|
|
|
Feb 20 2008, 04:45 AM
Post
#2
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
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: CODE $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: CODE <?php session_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: CODE <?php session_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, |
|
|
|
Feb 20 2008, 03:58 PM
Post
#3
|
|
|
Kinda N00B Group: Members Posts: 230 Joined: 13-January 08 From: Sweden Member No.: 27,579 |
"(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. |
|
|
|
Mar 1 2008, 03:51 AM
Post
#4
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
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:
CODE <?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: CODE <?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:Best regards, |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th December 2008 - 01:18 AM |