chanfuterboy Posted August 22, 2009 Share Posted August 22, 2009 hi, The sum of if when its first rate work fine. But when it is already, it keep printing the if and not the else why? With other words if ($get==0) $newrating = $get + $rating_post; else $newrating = ($get + $rating_post)/2; The else is not working when in db is more than 0 why? im doind something wrong because i dont get error see whole code below <?php ob_start(); include 'connect.php'; $id = $_GET['id']; // proses e ora bo primi submit if ($_POST['submit']) { // get datab $id_post = $_POST['id']; $rating_post = $_POST['rating']; $get = mysql_query("SELECT * animals WHERE id=$'id_post'"); $get = mysql_fetch_assoc($get); $get = $get['rating']; //echo $get. "<p />"; if ($get==0) $newrating = $get + $rating_post; else $newrating = ($get + $rating_post)/2; $update = mysql_query("UPDATE animals SET rating='$newrating' WHERE id='$id_post'"); header("Location: index.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/ Share on other sites More sharing options...
AngelicS Posted August 22, 2009 Share Posted August 22, 2009 Try this: $get = mysql_query("SELECT * animals WHERE id='$id_post'"); You had written WHERE id=$'id_post' the "$" should be inside the ' ' And also, you should start adding `` to table and column names, like this. $get = mysql_query("SELECT * `animals` WHERE `id`='$id_post'"); Best wishes //AngelicS Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904044 Share on other sites More sharing options...
chanfuterboy Posted August 22, 2009 Author Share Posted August 22, 2009 nop, not helped, it keep comming up with the if, and not the else, when the rate is more than 0 If i remove the if else. And put the devide code only, works, thus there is something in the else if statement Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904048 Share on other sites More sharing options...
AngelicS Posted August 22, 2009 Share Posted August 22, 2009 Try adding brackets to the else statement =) { } Best Wishes //AngelicS Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904054 Share on other sites More sharing options...
chanfuterboy Posted August 22, 2009 Author Share Posted August 22, 2009 i try it, but same result Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904056 Share on other sites More sharing options...
Zane Posted August 22, 2009 Share Posted August 22, 2009 instead of saying if($_POST['whatever']) do this if(isset($_POST['whatever']) && !empty($_POST['whatever'])) and yes...as mentioned earlier.. you are missing an opening bracket directly after else Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904063 Share on other sites More sharing options...
Daniel0 Posted August 22, 2009 Share Posted August 22, 2009 if(isset($_POST['whatever']) && !empty($_POST['whatever'])) In that case, the isset() is redundant. !empty($something) == true implies isset($something) == true. Always. Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904074 Share on other sites More sharing options...
AngelicS Posted August 22, 2009 Share Posted August 22, 2009 I just realized that you don't use $id = $_GET['id']; May it be that you are using $id_post = $_POST['id']; instead, by mistake? Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904081 Share on other sites More sharing options...
chanfuterboy Posted August 22, 2009 Author Share Posted August 22, 2009 the $_GET['id']; to get the link php?id=.... Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904088 Share on other sites More sharing options...
AngelicS Posted August 22, 2009 Share Posted August 22, 2009 You don't use it Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904090 Share on other sites More sharing options...
chanfuterboy Posted August 22, 2009 Author Share Posted August 22, 2009 yes, i use it, in the index, when it goes to the page that i send the problem Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904094 Share on other sites More sharing options...
AngelicS Posted August 23, 2009 Share Posted August 23, 2009 Can you just show me the code for the form, please? Best wishes //AngelicS Link to comment https://forums.phpfreaks.com/topic/171424-if-else-problem/#findComment-904356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.