Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Mysql Question(inserting Number From A Textfield)
Feelay
post Feb 19 2008, 05:53 PM
Post #1


Kinda N00B
Group Icon

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");
?>
Go to the top of the page
 
+Quote Post
TavoxPeru
post Feb 20 2008, 04:45 AM
Post #2


Super Member
Group Icon

Group: [HOSTED]
Posts: 805
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579
myCENTs:46.87



QUOTE(Feelay @ Feb 19 2008, 12:53 PM) *
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,
Go to the top of the page
 
+Quote Post
Feelay
post Feb 20 2008, 03:58 PM
Post #3


Kinda N00B
Group Icon

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.
Go to the top of the page
 
+Quote Post
TavoxPeru
post Mar 1 2008, 03:51 AM
Post #4


Super Member
Group Icon

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,
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. MySQL & PHP coding(9)
  2. Displaying Data From Mysql?(2)
  3. Php/mysql Data Display(3)
  4. Need Help With A PHP - MySQL Registration Script(13)
  5. Need For PHP/MySQL Creator(1)
  6. Printing Out A Table(6)
  7. Need Some Help Using PHP & MySQL(4)
  8. [PHP + MySQL] Separating The Results By Pages(0)
  9. [PHP + MySQL] Encrypting Data(11)
  10. [php] Index.php?section=xx&pag=yy(6)
  11. How Do You Create A Secure Loging?(4)
  12. Important: Basics Of Using PHP And MySQL(10)
  13. Need Help With Php/mysql And Web Servers Such As Asta's.(4)
  14. Need MySQL Alternative To The Syntax "or die()"(8)
  15. Re-order MySQL Table(11)
  1. PHP & MySQL: Displaying Content From A Given ID(6)
  2. How To Show Serial Nums In PHP Table For Contents Of MySQL DB(4)
  3. Php Mysql Errors(2)
  4. Sql Injection Prevention (passing Numerical Data Across Pages).(9)
  5. Php/mysql And Manual Page Caching?(4)
  6. Too Many Connections?(4)
  7. Extracting Mysql Maths Using Php(2)
  8. Anyone Know Of A Really Good Mysql Class?(4)
  9. Warning: Mysql_num_rows()(1)
  10. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...(4)
  11. Making A Link = Mysql_query(8)
  12. Making Something In Mysql Happen Only Once(10)
  13. Letting Users Add Mysql Data With Php(1)


 



- Lo-Fi Version Time is now: 5th December 2008 - 01:18 AM