supermerc Posted July 13, 2007 Share Posted July 13, 2007 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! Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 13, 2007 Share Posted July 13, 2007 try '".$holy."' something like that Quote Link to comment Share on other sites More sharing options...
d22552000 Posted July 13, 2007 Share Posted July 13, 2007 after every reply do: if (!*query name here*) { echo mysql_error(); } Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 13, 2007 Author Share Posted July 13, 2007 wat do u mean after each reply? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 13, 2007 Share Posted July 13, 2007 dude try this $sql = "UPDATE users SET holy = '".$holy."', arcane = '".$arcane."', shadow = '".$shadow."', fire = '".$fire."', kinetic = '".$kinetic."', points = '".$points."' WHERE owname = '".$owname."'"; Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 13, 2007 Author Share Posted July 13, 2007 nope, still not working Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 13, 2007 Share Posted July 13, 2007 <SELECT NAME="list"> $owname = $_POST['mylist']; either change the select name to mylist or change $owname to $_POST['list'] Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 13, 2007 Author Share Posted July 13, 2007 thx I fixed it but it still not working Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 13, 2007 Share Posted July 13, 2007 if (isset($_POST['submit'])) { maybe thats wrong your button name as Submit not submit Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 14, 2007 Author Share Posted July 14, 2007 ahh now it its putting it in database, but if i want to add some more, it clears the previous entry, i dont understand why Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 14, 2007 Share Posted July 14, 2007 WHERE owname = '$owname'"; maybe thats why you have lots of same owname you have to use the unique fields am i wrong then explain a bit more Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 14, 2007 Author Share Posted July 14, 2007 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? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 14, 2007 Share Posted July 14, 2007 $holy = $row['holy']+$holy2; is that an integer if not use concatenate . the dot Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 14, 2007 Author Share Posted July 14, 2007 ya they should both be numbers Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 14, 2007 Author Share Posted July 14, 2007 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.