HOME       >>       Programming

Mysql Question(inserting Number From A Textfield)


Feelay

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");?>


TavoxPeru

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,

Feelay

"(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.


TavoxPeru

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,


VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.