Jump to content

update query


supermerc

Recommended Posts

Hey, I made a code for a game, it keeps track of potions that users hand in and each potion has a point value so I made this code but its not working, it doesnt give me an error its just not updating anything in database.

 

this is my code

 

<?php

session_start();

require("config.php");

require("functions.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table border="0">
    <tr>
      <td width="61">Username</td>
      <td width="70"><img src="images/holy.gif" width="70" height="72" /></td>
      <td width="70"><img src="images/arcane.gif" width="70" height="72" /></td>
      <td width="70"><img src="images/shadow.gif" width="70" height="72" /></td>
      <td width="70"><img src="images/fire.gif" width="70" height="72" /></td>
      <td width="70"><img src="images/kinetic.gif" width="70" height="72" /></td>
      <td width="49">Submit</td>
    </tr>
    <tr>
      <td>
          <SELECT NAME="list">
          <?php
          $select = mysql_query("select * from users") or die ("Error:".mysql_error());
          while($row = mysql_fetch_array($select))
          {?>
          <OPTION VALUE="<?php echo $row['owname'];?>">
          <?php echo $row['owname'];?></OPTION>
          <?php
          }
          ?>
          </SELECT>
          </td>
      <td>Holy:
        <input name="holy" type="text" value="0" size="2" /></td>
      <td>Arcane:
        <input name="arcane" type="text" value="0" size="2" /></td>
      <td>Shadow:
      <input name="shadow" type="text" value="0" size="2" /></td>
      <td>Fire:
      <input name="fire" type="text" value="0" size="2" /></td>
      <td>Kinetic:
        <input name="kinetic" type="text" value="0" size="2" /></td>
      <td><input type="submit" name="Submit" value="Submit" /></td>
    </tr>
  </table>
</form>
<?
if (isset($_POST['submit'])) {

        // Should escape user entry so they don't break sql queries

        $owname = $_POST['mylist'];

        $holy2 = mysql_escape_string($_POST['holy']);
        
    $arcane2 = mysql_escape_string($_POST['arcane']);
        
        $shadow2 = mysql_escape_string($_POST['shadow']);
        
        $fire2 = mysql_escape_string($_POST['fire']);
        
        $kinetic2 = mysql_escape_string($_POST['kinetic']);
        
        $holy = $row['holy']+$holy2;
        
        $arcane = $row['arcane']+$arcane2;
        
        $shadow = $row['shadow']+$shadow2;
        
        $fire = $row['fire']+$fire2;
        
        $kinetic = $row['kinetic']+$kinetic2;
        
        $points2 = $row['points'];
        
        $points3 = $holy2*1+$arcane2*2+$shadow2*3+$fire2*4+$kinetic2*5;
        
        $points = $points2+$points3;

    
        // Create mySQL query - easier for when needing to debug queries

        $sql = "UPDATE users SET holy = '$holy', arcane = '$arcane', shadow = '$shadow', fire = '$fire', kinetic = '$kinetic', points = '$points' WHERE owname = '$owname'";

        // Execute Query

        $qry = mysql_query($sql) or die("MySQL Error: <br /> {$sql} <br />". mysql_error());

}
?>

</body>
</html> 

 

Thanks a lot for the help!

Link to comment
https://forums.phpfreaks.com/topic/59880-update-query/
Share on other sites

no they cant theres only 1

 

What i mean is I have for example

 

$holy2 = mysql_escape_string($_POST['holy']);

 

Which is the number of holy being handed out now

 

then

 

$holy = $row['holy']+$holy2;

 

Which is the number of holy already in because we called all the things in users earlier and its in there, plus holy 2 which is what was handed in so it should add up?

Link to comment
https://forums.phpfreaks.com/topic/59880-update-query/#findComment-297810
Share on other sites

I thought that the problem might be that when i called it before, it didnt get the number of potions that the user had before because where was no, were owname = '$_POST[mylist]' so lower i put

$owname = $_POST['mylist'];  
  $select2 = mysql_query("select * from users where owname='$owname'") or die ("Error:".mysql_error());
  while($row2 = mysql_fetch_array($select2))
  {
}

and i though it would fix it but it didnt :(

 

Here is total code once again

 

<?php

session_start();

require("config.php");

require("functions.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table border="0">
    <tr>
      <td width="61">Username</td>
      <td width="70"><img src="images/holy.gif" width="70" height="72" /></td>
      <td width="70"><img src="images/arcane.gif" width="70" height="72" /></td>
      <td width="70"><img src="images/shadow.gif" width="70" height="72" /></td>
      <td width="70"><img src="images/fire.gif" width="70" height="72" /></td>
      <td width="70"><img src="images/kinetic.gif" width="70" height="72" /></td>
      <td width="49">Submit</td>
    </tr>
    <tr>
      <td>
  <SELECT NAME="mylist">
  <?php
  $select = mysql_query("select * from users") or die ("Error:".mysql_error());
  while($row = mysql_fetch_array($select))
  {?>
  <OPTION VALUE="<?php echo $row['owname'];?>">
  <?php echo $row['owname'];?></OPTION>
  <?php
  }
  ?>
  </SELECT>
  </td>
      <td>Holy:
        <input name="holy" type="text" value="0" size="2" /></td>
      <td>Arcane:
        <input name="arcane" type="text" value="0" size="2" /></td>
      <td>Shadow:
      <input name="shadow" type="text" value="0" size="2" /></td>
      <td>Fire:
      <input name="fire" type="text" value="0" size="2" /></td>
      <td>Kinetic:
        <input name="kinetic" type="text" value="0" size="2" /></td>
      <td><input type="submit" name="Submit" value="Submit" /></td>
    </tr>
  </table>
</form>
  <?php
      	$owname = $_POST['mylist'];  
  $select2 = mysql_query("select * from users where owname='$owname'") or die ("Error:".mysql_error());
  while($row2 = mysql_fetch_array($select2))
  {
}?>
<?
if (isset($_POST['Submit'])) {

// Should escape user entry so they don't break sql queries



$holy2 = mysql_escape_string($_POST['holy']);

    $arcane2 = mysql_escape_string($_POST['arcane']);

$shadow2 = mysql_escape_string($_POST['shadow']);

$fire2 = mysql_escape_string($_POST['fire']);

$kinetic2 = mysql_escape_string($_POST['kinetic']);

$holy = $row2['holy']+$holy2;

	$arcane = $row2['arcane']+$arcane2;

$shadow = $row2['shadow']+$shadow2;

$fire = $row2['fire']+$fire2;

$kinetic = $row2['kinetic']+$kinetic2;

$points2 = $row2['points'];

$points3 = $holy2*1+$arcane2*2+$shadow2*3+$fire2*4+$kinetic2*5;

$points = $points2+$points3;

    
// Create mySQL query - easier for when needing to debug queries

$sql = "UPDATE users SET holy = '".$holy."', arcane = '".$arcane."', shadow = '".$shadow."', fire = '".$fire."', kinetic = '".$kinetic."', points = '".$points."' WHERE owname = '".$owname."'";

// Execute Query

$qry = mysql_query($sql) or die("MySQL Error: <br /> {$sql} <br />". mysql_error());

}
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/59880-update-query/#findComment-297845
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.