Syntax error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Syntax error

Post by kkonline »

Code: Select all

echo "<form action='pages.php?page=2 method='post'><select name='rates'><option value='x' selected>Rate me</option><option value='10'>10</option><option value='9'>9</option><option value='8'>8</option><option value='7'>7</option><option value='6'>6</option><option value='5'>5</option><option value='4'>4</option><option value='3'>3</option><option value='2'>2</option><option value='1'>1</option></select><input type='hidden' name='rateit_id' value='100'><input type='hidden' name='action' value='doit'> &nbsp;<input type='submit' value='Rate!'></form>"; 

if($_POST['action'] == "doit")
 {
  if($_POST['rates']>0 && $_POST['rates']<11 && !empty($_POST['rateit_id']))
  {
$new_count = ($row['votes'] + 1); 
            $tut_rating2 = ($row['rates'] * $row['votes']); 
            $new_rating = (($_POST['rates'] + $tut_rating2) / ($new_count)); 
            $new_rating2 = number_format($new_rating, 2, '.', ''); 

 $edit = "UPDATE wow SET 
 rating='$new_rating2',votes='$new_count' WHERE id = $id";
 $result = mysql_query($edit) or die (mysql_error());
    
    // did it work?
    if ($result) {
        echo 'Thank you for rating this article.<br /><br />';
    } else {
        echo 'Error! The values sent are below.<br /><br />';
        
    }


   echo $row['votes'];
  }
 }
It gives me Notice: Undefined index: action in c:\program files\easyphp1-8\www\pages.php on line 85 when i access pages.php?page=2
and when i click on rate it gives

Undefined variable: id in c:\program files\easyphp1-8\www\pages.php on line 95
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Syntax error

Post by Christopher »

kkonline wrote:It gives me Notice: Undefined index: action in c:\program files\easyphp1-8\www\pages.php on line 85 when i access pages.php?page=2
and when i click on rate it gives

Code: Select all

if(isset($_POST['action']) && ($_POST['action'] == "doit"))
Undefined variable: id in c:\program files\easyphp1-8\www\pages.php on line 95
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2[/quote]
The variable $id is not assigned a value before it is used.
(#10850)
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Re: Syntax error

Post by kkonline »

Now, how do i change the ratings in the db. Currently it doesnot count the votes (after any no. of votes just say votes=1 in db and the rating is the last rating which is set and not the average of the ratings as it should be the cumulative way.)

Code: Select all

if($_POST['rates']>0 && $_POST['rates']<11 &&!empty($_POST['rateit_id']))
{
$new_count = ($row['votes'] + 1);
$tut_rating2 = ($row['rates'] * $row['votes']);
$new_rating = (($_POST['rates'] + $tut_rating2) / ($new_count));
$new_rating2 = number_format($new_rating, 2, '.', '');

$edit = "UPDATE wow SET
rating='$new_rating2',votes='$new_count' WHERE id = $page";
$result = mysql_query($edit) or die (mysql_error());
secondly echo "<form action='$SERVER['PHP_SELF']' method='post'></form>";
gives me a syntax error
Post Reply