Jump to content

if else problem


chanfuterboy

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.