tags:

views:

70

answers:

4
function add_new($father,$chName)  // add new category
{

    if($father = "1" ) {


$result = mysql_query("INSERT into stinky_menu (title,nest_under)
     VALUES('".$chName."','1')");

    } 
     else { 

$result = mysql_query("UPDATE stinky_menu SET title  = '$chName' nest_under = '$father'");

     }

 }

I am getting the value of father from parent page, but its not going to else condition if its not equal to one.

+2  A: 

Try:

if ($father == 1){}

Read here about comparison operators. "=" is the assignment operator.

Look at this to see what your code does:

<?php
    $father = 55;

    if ($father = 1){}
    else{}

    echo $father;
?>

This prints "1".

+4  A: 

You’re using the assignment operator = rather than the comparison operator ==. So try this:

if ($father == "1") {
    // …
} else {
    // …
}
Gumbo
One way to avoid that kind of typo/error is to "reverse" the condition, like this : if ('1' == $father) {...}This way, if you put only one '=', you'll get a Parse error, and immediatly notice the problem.
Pascal MARTIN
+3  A: 

That's because you have

if($father = "1")

You need to use "==". "=" is the assignment operator. You are setting $father equal to "1" even when it isn't.

Mike
A: 

Also, should not that last query be:

"UPDATE stinky_menu SET title  = '$chName', nest_under = '$father'"
eckberg