ArcAiN6 Posted October 5, 2007 Share Posted October 5, 2007 I am currently in the midst of writing some code for a site I'm building, and perhaps it's because it's so late, or perhaps I've gotten in over my head. But i simply can't figure this out. The code is supposed to select a user from the database by name in a drop down menu (that works fine) display their current total of dkp (this function is also working correctly) and then offer the admin an opportunity to update / add to the current total of DKP for the user (this is NOT working at all) following is the code. any help in this matter would be most appreciated. Thank you for your time ArcAiN6 <? // Connect database mysql_connect("localhost","myDBuser","myDBpass"); mysql_select_db("myDBname"); // If submitted, check the value of "select". If its not blank value, get the value and put it into $select. if(isset($_GET['select'])&& $_GET['select'] !=""){ $select=$_GET['select']; } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> "> <h4>Select Toon's Name :</h4> <select name="select"> <option value="">--- Select ---</option> <? // Get records from database (table "e107_user_extended"). $list=mysql_query("select * from e107_user_extended order by user_extended_id asc"); // Show records by while loop. while($row_list=mysql_fetch_assoc($list)){ ?> <option value="<? echo $row_list['user_extended_id']; ?>" <? if($row_list['user_extended_id']==$select){ echo "selected"; } ?>> <? echo $row_list['user_toonm']; ?></option> <? // End while loop. } ?> </select> <input type="submit" name="Submit" value="Select" /> </form> <hr> <p> <? // If you have selected from list box. if(isset($select)&&$select!=""){ // Get records from database (table "e107_user_extended"). $result=mysql_query("select * from e107_user_extended where user_extended_id='$select'"); while ($row = mysql_fetch_assoc($result)) { echo ' User - Current DKP<strong>' . '<p>' . $row['user_toonm'] . " - " . $row['user_DKP'] . '</p>'; } } echo '<br><br><h3>Update this Toon\'s DKP\?<h3><br>'; if(isset($_POST['dkp'])&& $_POST['dkp'] !=""){ $dkp=$_POST['dkp']; } ?> <form id='form2' name='form2' action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label><h3>Type total DKP earned here:</h3><br /> (for example joe has 10dkp, and he earned 3 dkp tonight, input 3 into the field)<br> <input name="dkp" type="text" value="0" size="8" maxlength="8"> </label><br /> <input type="submit" value="SUBMIT" /> </form> <? //check that the input is actually a number // Execute update $sql = 'UPDATE user_extended SET user_DKP = user_DKP + $dkp WHERE user_extended_id = $select'; // Close database connection. mysql_close(); ?> </p> </body> </html> Quote Link to comment Share on other sites More sharing options...
ArcAiN6 Posted October 5, 2007 Author Share Posted October 5, 2007 ok... so i was having a tard moment... the database name wasn't correct, and also there was nothing to actually empliment the changes... now that i've solved those two problems, i'm getting an error message... following is an altered post (evidently 15mins is too long to wait to modify my post above ) I am currently in the midst of writing some code for a site I'm building, and perhaps it's because it's so late, or perhaps I've gotten in over my head. But i simply can't figure this out. The code is supposed to select a user from the database by name in a drop down menu (that works fine) display their current total of dkp (this function is also working correctly) and then offer the admin an opportunity to update / add to the current total of DKP for the user (this is NOT working at all) it also returns an error " Error adding submitted DKP: Unknown column '$select' in 'where clause' " following is the code. any help in this matter would be most appreciated. Thank you for your time ArcAiN6 <? // Connect database mysql_connect("localhost","myDBusername","myDBpass"); mysql_select_db("myDBname"); // If submitted, check the value of "select". If its not blank value, get the value and put it into $select. if(isset($_GET['select'])&& $_GET['select'] !=""){ $select=$_GET['select']; } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> "> <h4>Select Toon's Name :</h4> <select name="select"> <option value="">--- Select ---</option> <? // Get records from database (table "e107_user_extended"). $list=mysql_query("select * from e107_user_extended order by user_extended_id asc"); // Show records by while loop. while($row_list=mysql_fetch_assoc($list)){ ?> <option value="<? echo $row_list['user_extended_id']; ?>" <? if($row_list['user_extended_id']==$select){ echo "selected"; } ?>> <? echo $row_list['user_toonm']; ?></option> <? // End while loop. } ?> </select> <input type="submit" name="Submit" value="Select" /> </form> <hr> <p> <? // If you have selected from list box. if(isset($select)&&$select!=""){ // Get records from database (table "e107_user_extended"). $result=mysql_query("select * from e107_user_extended where user_extended_id='$select'"); while ($row = mysql_fetch_assoc($result)) { echo ' User - Current DKP<strong>' . '<p>' . $row['user_toonm'] . " - " . $row['user_DKP'] . '</p>'; } } echo '<br><br><h3>Update this Toon\'s DKP?<h3><br>'; if(isset($_POST['dkp'])&& $_POST['dkp'] !=""){ $dkp=$_POST['dkp']; } ?> <form id='form2' name='form2' action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label><h3>Type total DKP earned here:</h3><br /> (for example joe has 10dkp, and he earned 3 dkp tonight, input 3 into the field)<br> <input name="dkp" type="text" value="0" size="8" maxlength="8"> </label><br /> <input type="submit" value="SUBMIT" /> </form> <? //check that the input is actually a number // Execute update $sql = 'UPDATE e107_user_extended SET user_DKP = user_DKP + $dkp WHERE user_extended_id = $select'; if (@mysql_query($sql)) { echo '<p>DKP has been added.</p>'; } else { echo '<p>Error adding submitted DKP: ' . mysql_error() . '</p>'; } // Close database connection. mysql_close(); ?> </p> </body> </html> Quote Link to comment Share on other sites More sharing options...
Aeglos Posted October 5, 2007 Share Posted October 5, 2007 In here: $sql = 'UPDATE user_extended SET user_DKP = user_DKP + $dkp WHERE user_extended_id = $select'; Use double quotes when evaluating variables inside a string, like this: $sql = "UPDATE user_extended SET user_DKP = user_DKP + $dkp WHERE user_extended_id = $select"; or else escape the string like in the rest of your code: $sql = 'UPDATE user_extended SET user_DKP = user_DKP + '.$dkp.' WHERE user_extended_id = '.$select; And you are not "executing" that sql statement anywhere, as in your missing this: mysql_query($sql); Quote Link to comment Share on other sites More sharing options...
ArcAiN6 Posted October 5, 2007 Author Share Posted October 5, 2007 hrm.... that did seem to change the error message a bit now i'm recieving: rror adding submitted DKP: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_extended_id =' at line 1 and if i try to continue and select a user i recieve this error: Error adding submitted DKP: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_extended_id = 1' at line 1 i think after i fix the syntax issue, i'll need to do something to hide / not parse the rest of the code untill a user is selected, and an input posted by the user. as it sits now, it appears to be trying to do the whole script on every loading of the page.. Quote Link to comment Share on other sites More sharing options...
ArcAiN6 Posted October 6, 2007 Author Share Posted October 6, 2007 i got it $sql = "UPDATE e107_user_extended SET user_DKP = user_DKP + '$dkp' WHERE user_extended_id = 1"; WooT! Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted October 7, 2007 Share Posted October 7, 2007 Topic Solved Quote Link to comment Share on other sites More sharing options...
ArcAiN6 Posted October 9, 2007 Author Share Posted October 9, 2007 crap... not fixed... //is NOT correct... this actually selects the first id in the table... $sql = "UPDATE e107_user_extended SET user_DKP = user_DKP + '$dkp' WHERE user_extended_id = 1"; //DOES NOT WORK $sql = "UPDATE e107_user_extended SET user_DKP = user_DKP + '$dkp' WHERE user_extended_id = '$select' "; //also does not work $sql = "UPDATE e107_user_extended SET user_DKP = user_DKP + '$dkp' WHERE user_extended_id = '.$select.' "; Quote Link to comment Share on other sites More sharing options...
hungryOrb Posted October 9, 2007 Share Posted October 9, 2007 Perhaps the bigger question is, why are you still using DKP? Quote Link to comment Share on other sites More sharing options...
ArcAiN6 Posted October 9, 2007 Author Share Posted October 9, 2007 wow.. that was very insightful to the problem at hand, i'll be sure to use that information the next time i have a real crisis on my hands... Quote Link to comment Share on other sites More sharing options...
Aeglos Posted October 10, 2007 Share Posted October 10, 2007 $sql = "UPDATE e107_user_extended SET user_DKP = user_DKP + '$dkp' WHERE user_extended_id = '".$select."' "; Try that, dunno... might work. 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.