Gayner Posted September 5, 2009 Share Posted September 5, 2009 <?php function test(){ mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id={$ibforums->member["id"]} LIMIT 1"); } ?> case 3: content='You won this round. <?php echo test(); ?>'; It doesn'tw ork? whY? Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 mysql_query is a resource. You must fetch the data using mysql_fetch_array/mysql_fetch_assoc/mysql_fetch_row (although I don't recommend using the latter of the three. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 5, 2009 Share Posted September 5, 2009 mysql_query is a resource. You must fetch the data using mysql_fetch_array/mysql_fetch_assoc/mysql_fetch_row (although I don't recommend using the latter of the three. Gayner is running an UPDATE statement which doesn't return any results. So these functions will not serve any purpose. <?php function test(){ mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id={$ibforums->member["id"]} LIMIT 1"); } ?> case 3: content='You won this round. <?php echo test(); ?>'; It doesn'tw ork? whY? What are expecting to be returned from your test() function? What are you trying to do. Functions do not return anything unless you tell it to. Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 mysql_query is a resource. You must fetch the data using mysql_fetch_array/mysql_fetch_assoc/mysql_fetch_row (although I don't recommend using the latter of the three. Gayner is running an UPDATE statement which doesn't return any results. So these functions will not serve any purpose. <?php function test(){ mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id={$ibforums->member["id"]} LIMIT 1"); } ?> case 3: content='You won this round. <?php echo test(); ?>'; It doesn'tw ork? whY? What are expecting to be returned from your test() function? What are you trying to do. Functions do not return anything unless you tell i t to. Can u tell me how to make it return that query? lol thanks Quote Link to comment Share on other sites More sharing options...
corbin Posted September 5, 2009 Share Posted September 5, 2009 Update queries don't return anything, as previously stated. What data are you trying to get? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 5, 2009 Share Posted September 5, 2009 UPDATE queries do not return any results. However you can use the function called mysql_affected_rows which returns the number of rows your query affected. For a fuctuion to return any thing you need to use the return keyword. As explained in the manual. Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 Update queries don't return anything, as previously stated. What data are you trying to get? Not trying to get any data, just update.. That case 3 is run from: if(isplayer){ playerwins[level]++; playerstarts=true; writetext(3); }else{/code] it's a Tic tac toe script.. I want that user to get points+0.25 each time they win tic tac to game, it's javascript based.. im triyn to implent php to it Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 ...I don't know how I didn't catch that. Anyway, I suppose he could be trying to use mysql_affected_rows or mysql_info? Just a stab in the dark. Warning - while you were typing a new reply has been posted. You may wish to review your post. You could use something like this: <?php function test(){ global $sql; $sql = "UPDATE ibf_members SET points = points+0.25 WHERE id={$ibforums->member["id"]} LIMIT 1"; mysql_query($sql); } ?> case 3: content='You won this round. <?php echo $sql; ?>'; Quote Link to comment Share on other sites More sharing options...
corbin Posted September 5, 2009 Share Posted September 5, 2009 Errr bundyxc unless $sql were also defined in the global scope, that wouldn't echo anything. Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 Errr bundyxc unless $sql were also defined in the global scope, that wouldn't echo anything. About to say that it didn't work lol Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 function test(){ $sql = "UPDATE ibf_members SET points = points+0.25 WHERE id={$ibforums->member["id"]} LIMIT 1"; return $sql; } I did this and then i did case 3: content='You won this round. <?php echo test(); ?>'; but it spits it out as text? You won this round. UPDATE ibf_members SET points = points+0.25 WHERE id= LIMIT 1 ?? Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 I changed my code. Wait, what did you want it to do...? Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 I changed my code. Wait, what did you want it to do...? Run that query EDIT: but it's echoing it out in text as my above post `` Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 5, 2009 Share Posted September 5, 2009 Yes. Thats correct. That is exactly how you have coded your function to behave To be able to run your update query you need to use the mysql_query function, as you was using it previously. Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 OK i changed it to: <?php function test(){ $sql = mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id={$ibforums->member["id"]} LIMIT 1"); return $sql; } ?> Now when I win my tic tac toe game it doesn't spit it out as text, but it doesnt run, lol HMM ??? Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 ...wow. <?php function test(){ $sql = "UPDATE `ibf_members` SET `points` = points+0.25 WHERE id='" . $ibforums->member['id'] . "' LIMIT 1"; mysql_query($sql); return $sql; } ?> Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 ...wow. <?php function test(){ $sql = "UPDATE `ibf_members` SET `points` = points+0.25 WHERE id='" . $ibforums->member['id'] . "' LIMIT 1"; mysql_query($sql); return $sql; } ?> Like I said bro that spit's out plain text... My way doesn't split out plain text so i know it's closer then worker then urs sorry Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 5, 2009 Share Posted September 5, 2009 Your function doesnt display anything as mysql_query does not return anything! However the query is running, provided you have connection to mysql first of course. Hold on I just noticed something your function should actually be <?php function test($memberID) { return mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id={$memberID} LIMIT 1"); } if(test($ibforums->member["id"])) { echo 'You won this round'; } else { echo 'Error! unable to update player points! For member id - '. $ibforums->member["id"]; } ?> Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 Your function doesnt display anything as mysql_query does not return anything! However the query is running, provided you have connection to mysql first of course. Hold on I just noticed something your function should actually be <?php function test($memberID) { return mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id={$memberID} LIMIT 1"); } if(test($ibforums->member["id"])) { echo 'You won this round'; } else { echo 'Error! unable to update player points! For member id - '. $ibforums->member["id"]; } ?> LOL Sir, i have included a full SDK.. <?php // Load and Start IPB SDK require_once "ipbsdk/ipbsdk_class.inc.php"; $SDK =& new IPBSDK(); global $ibforums, $DB; ?> This is were all my functions ipbsdk_class.inc is over 100kilobytes big it has everything i need in there, I can use global functions like {$ibforums->member["id"]} for my username id etc.. or any row from database, lol And the query works if it doesn't get called from a function or from this javascript: case 3: content='You won this round. <?php echo test(); ?>'; That ^^ function is called from: if(iswon){ if(isplayer){ playerwins[level]++; playerstarts=true; writetext(3); }else{ pcwins[level]++; playerstarts=false; writetext(2); }} Writetext(3) see Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 haha, I was just writing a function to do the same thing wildteen88. function test($id) { $query = mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id=" . $id . " LIMIT 1"); if($query) { print('You won this round'); } else { print('MySQL has encountered an error: ' . mysql_error()); } } And then use this in the page: case 3: content='You won this round. <?php echo test(); ?>'; (Just like the code you used before) Warning - while you were typing a new reply has been posted. You may wish to review your post. Wait, what about your SDK? Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 haha, I was just writing a function to do the same thing wildteen88. function test($id) { $query = mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id=" . $id . " LIMIT 1"); if($query) { print('You won this round'); } else { print('MySQL has encountered an error: ' . mysql_error()); } } And then use this in the page: case 3: content='You won this round. <?php echo test(); ?>'; (Just like the code you used before) Warning - while you were typing a new reply has been posted. You may wish to review your post. Wait, what about your SDK? were u getting $id from? lol Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 WOW Screw it it wont work php and javascript suck together man, lol Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 Just use this script, okay? function query($id) { $query = mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id=" . $id . " LIMIT 1"); if($query) { print('You won this round.'); } else { print('MySQL has encountered an error: ' . mysql_error()); } } case 3: content='You won this round. <?php print(query($ibforums->member['id'])); ?>'; Quote Link to comment Share on other sites More sharing options...
Gayner Posted September 5, 2009 Author Share Posted September 5, 2009 Just use this script, okay? function query($id) { $query = mysql_query("UPDATE ibf_members SET points = points+0.25 WHERE id=" . $id . " LIMIT 1"); if($query) { print('You won this round.'); } else { print('MySQL has encountered an error: ' . mysql_error()); } } case 3: content='You won this round. <?php print(query($ibforums->member['id'])); ?>'; It wont work because $id is not found.. anywere EDIT: I saw ur edit sec Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 5, 2009 Share Posted September 5, 2009 Oh, well then I'm sure you wouldn't mind posting the error message you received? I mean, you did try it, right? 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.