Jump to content

Recommended Posts

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);
}

Link to comment
https://forums.phpfreaks.com/topic/98782-whats-wrong-with-this-code/
Share on other sites

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?

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!

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

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());

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 "

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.