newttster Posted April 1, 2012 Posted April 1, 2012 Why is this not posting to the database? I have verified that all the names in the table and the table name itself are correct. Default for "grosetonesone" is 0. Type is tinyint-2. function tonestage_one() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT grosetonesone FROM stagetable WHERE userid = {$ir['userid']}"); $r=$db->fetch_row($q); if ($r['grosetonesone']==0) { echo "Yada yada yada blah blah blah.<br /> <a href='explore.php'>Back to town<a/><br />"; $db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`='{$ir['userid']}'", $c); } else { echo"Why are you here? You have already done this."; } } Quote
HauntedDawg Posted April 1, 2012 Posted April 1, 2012 $db->query('UPDATE `stagetable` WHERE `grosetonesone` = 1 WHERE `userid` = '.$ir['userid']); Quote
Guest Posted April 1, 2012 Posted April 1, 2012 $db->query('UPDATE `stagetable` WHERE `grosetonesone` = 1 WHERE `userid` = '.$ir['userid']); That wouldn't work Try $db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`= '".$ir['userid']."'", $c) or die(mysql_error()); If you get an error from using the above then post it here. Quote
Damagedcity.com Posted April 1, 2012 Posted April 1, 2012 $db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`='".$ir['userid']."'", $c); This will work too :) Quote
sniko Posted April 1, 2012 Posted April 1, 2012 @iExze & Newttster - I'd like to question both of your methods, this time I used your advice ;) You have the following [...]WHERE `userid`= '".$ir['userid']."'"[..] So, My question. Why encase a numerical value in apostrophes ( ' ) thus making the program treat it as a string? Here's how I would do it; $db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`=". $userid, $c) or die(mysql_error()); I would, after confirmation that it works, remove the or die(mysql_error()) as it won't be needed. Quote
rulerofzu Posted April 1, 2012 Posted April 1, 2012 Sniko as they have seen others use such here. Personally I think your better troubleshooting by using a variable and then you can print the results to see why your query is not working. So $var=$db->query..... print_r($var) Quote
Guest Posted April 1, 2012 Posted April 1, 2012 @iExze & Newttster - I'd like to question both of your methods, this time I used your advice ;) You have the following [...]WHERE `userid`= '".$ir['userid']."'"[..] So, My question. Why encase a numerical value in apostrophes ( ' ) thus making the program treat it as a string? Here's how I would do it; $db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`=". $userid, $c) or die(mysql_error()); I would, after confirmation that it works, remove the or die(mysql_error()) as it won't be needed. I encase everything like that, whether a number or string, it's habbit really. Quote
newttster Posted April 1, 2012 Author Posted April 1, 2012 (edited) Okay everyone ... I have tried all of your suggestions and it still will not post to the db. It does not give me an error message. @ruler - I did as you suggested and all it is doing is printing out is a 1 after the <a href='explore.php'>Back to town<a/>"; @sniko - I encase the values because every once in a while the query that I am attempting to do will not recognize it without the quotes. So as a fail safe, I always do this now. *shrugs* I have thought of doing an INSERT INTO ... the problem with that is there will come a time when the table itself will have too many rows to make this feasible ... which is why I am trying to get the UPDATE to work. EDIT: On reflection, with the INSERT INTO after the userid value the rest would just be 0 or 1. This does work as I have tested it ... it's just that after a certain point doing the INSERT with all the 1's and 0's will get annoying which is why I was trying to get the UPDATE to work. Which would you use? Edited April 1, 2012 by newttster Quote
rulerofzu Posted April 1, 2012 Posted April 1, 2012 Thought about doing an INSERT. So the table your trying to update does not have the info? you cannot update something that does not exist you do realize that dont you. Quote
newttster Posted April 1, 2012 Author Posted April 1, 2012 Thought about doing an INSERT. So the table your trying to update does not have the info? you cannot update something that does not exist you do realize that dont you. *facepalms* I do now. Grr! So as long as I do one INSERT query to start that contains the users ID ... after that I can simply do an UPDATE from then on? My apologies ... that completely got by me all together. Colour me embarassed. Quote
rulerofzu Posted April 1, 2012 Posted April 1, 2012 Yeah a simple check to see if the user is in the table will suffice. If they are update if not insert. Quote
newttster Posted April 1, 2012 Author Posted April 1, 2012 Got it. Thanks so much for everyone's input ... and sorry for having wasted your time on this. Quote
HauntedDawg Posted April 2, 2012 Posted April 2, 2012 That wouldn't work Try $db->query("UPDATE `stagetable` SET `grosetonesone`= '1' WHERE `userid`= '".$ir['userid']."'", $c) or die(mysql_error()); If you get an error from using the above then post it here. Please don't quote my work. Putting quote's around numerical value's? Shame. Test my code, fool Quote
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.