leeandrew Posted March 31, 2008 Share Posted March 31, 2008 This should check for value for field selected; if exists - 1, if not + 1. Its not working, can someone help me? $query="IF EXISTS ( SELECT `top".$_POST['bookmark_number']."` FROM `voting_items` WHERE `top".$_POST['bookmark_number']."` = '".$_POST['page']."' ) UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST ['bookmark_number']."` - 1 WHERE `name` = '".$_POST['page'].' ELSE UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST ['bookmark_number']."` + 1 WHERE `name` = '".$_POST['page'].'"; mysql_query($query); $query2="UPDATE `pluserdata` SET `top".$_POST['bookmark_number']."` = '".$_POST['page']."' WHERE `userid` = '".$User->userid."';"; mysql_query($query2); } Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/ Share on other sites More sharing options...
MadTechie Posted March 31, 2008 Share Posted March 31, 2008 add some error catching mysql_query($query2) on die(mysql_error()); as for the SQL statement.. i think you need to rethink it a little.. http://dev.mysql.com/doc/refman/5.1/en/index.html Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505474 Share on other sites More sharing options...
leeandrew Posted March 31, 2008 Author Share Posted March 31, 2008 I've changed it to this without any luck: }elseif(isset($_POST['bookmark_number'])){ $query="IF EXISTS ( SELECT `top".$_POST['bookmark_number']."` FROM `voting_items` WHERE `top".$_POST['bookmark_number']."` = '".$_POST['page']."' )"; $minus="UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST['bookmark_number']."` - 1 WHERE `name` = '".$_POST['page'].'"; mysql_query($minus); }ELSE{ $add="UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST['bookmark_number']."` + 1 WHERE `name` = '".$_POST['page'].'"; mysql_query($add); $query2="UPDATE `pluserdata` SET `top".$_POST['bookmark_number']."` = '".$_POST['page']."' WHERE `userid` = '".$User->userid."';"; mysql_query($query2); } Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505555 Share on other sites More sharing options...
MadTechie Posted March 31, 2008 Share Posted March 31, 2008 add some error catchin add some error catching mysql_query($query2) on die(mysql_error()); as for the SQL statement.. i think you need to rethink it a little.. http://dev.mysql.com/doc/refman/5.1/en/index.html "without anyluck" doesn't really help need more info! Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505558 Share on other sites More sharing options...
leeandrew Posted March 31, 2008 Author Share Posted March 31, 2008 get this error: Parse error: syntax error, unexpected T_STRING Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505563 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2008 Share Posted March 31, 2008 Please post the whole error message with the line number. Also post that line and the 10 or so lines surrounding it, indicating which line got the error. These errors usually indicate that there is an unmatched quote or a forgotten semi-colon on a line somewhere above the line indicated. Ken Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505569 Share on other sites More sharing options...
leeandrew Posted March 31, 2008 Author Share Posted March 31, 2008 error on line 122 lines 112-132: $query="IF EXISTS ( SELECT `top".$_POST['bookmark_number']."` FROM `voting_items` WHERE `top".$_POST['bookmark_number']."` = '".$_POST['page']."' )"; $minus="UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST['bookmark_number']."` - 1 WHERE `name` = '".$_POST ['page'].'"; mysql_query($minus); }ELSE{ $add="UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST['bookmark_number']."` + 1 WHERE `name` = '".$_POST['page'].'"; mysql_query($add); $query2="UPDATE `pluserdata` SET `top".$_POST['bookmark_number']."` = '".$_POST['page']."' WHERE `userid` = '".$User->userid."';"; mysql_query($query2) on die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505575 Share on other sites More sharing options...
stopblackholes Posted March 31, 2008 Share Posted March 31, 2008 remove the extra ; $query2="UPDATE `pluserdata` SET `top".$_POST['bookmark_number']."` = '".$_POST['page']."' WHERE `userid` = '".$User->userid."';"; mysql_query($query2); } Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505577 Share on other sites More sharing options...
MadTechie Posted March 31, 2008 Share Posted March 31, 2008 that wouldn't case this problem, also please post more than 4 line! Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505579 Share on other sites More sharing options...
leeandrew Posted March 31, 2008 Author Share Posted March 31, 2008 this is all data between 2 echo statements: </table>'; }elseif(isset($_POST['bookmark_number'])){ $query="IF EXISTS ( SELECT `top".$_POST['bookmark_number']."` FROM `voting_items` WHERE `top".$_POST['bookmark_number']."` = '".$_POST['page']."' )"; $minus="UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST['bookmark_number']."` - 1 WHERE `name` = '".$_POST ['page'].'"; mysql_query($minus); }ELSE{ $add="UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST['bookmark_number']."` + 1 WHERE `name` = '".$_POST['page'].'"; mysql_query($add); $query2="UPDATE `pluserdata` SET `top".$_POST['bookmark_number']."` = '".$_POST['page']."' WHERE `userid` = '".$User->userid."';"; mysql_query($query2) on die(mysql_error()); } if(!isset($User->userid)){ echo "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>"; exit; } $row=mysql_fetch_object(mysql_query("select * from pluserdata where userid='$User->userid'")); echo " Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505584 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2008 Share Posted March 31, 2008 You will find your errors much easier if you don't break up the lines in an unnatural way. Your syntax error is on this line: <?php $minus="UPDATE `voting_items` SET `top".$_POST['bookmark_number']."` = `top".$_POST['bookmark_number']."` - 1 WHERE `name` = '".$_POST ['page'].'"; ?> you end the line with a .'" when it should be ."'" Ken Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-505588 Share on other sites More sharing options...
leeandrew Posted April 3, 2008 Author Share Posted April 3, 2008 changing that just gives the -1 query every time. I want to be able to check if exists, before doing either -1 or +1 Quote Link to comment https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/#findComment-508735 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.