Jump to content
xisto Community
Feelay

Mysql Question(inserting Number From A Textfield)

Recommended Posts

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

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

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 Integer

Best regards,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.