Jump to content

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

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.