tags:

views:

144

answers:

7
 function updateDemo($demoTitle, $desc, $keyword, $linkTitle, $clientname, 
         $imageTitle, $adminName, $demoID)  {   

    $query = "UPDATE demos SET demoTitle ='$demoTitle' , dmDesc = '$desc' , 
    dmKey = '$keyword' , dmLink= '$linkTitle' , 
    client='$clientname' , imageTitle = '$imageTitle' , 
     userName = '$adminName' WHERE id = '$demoID'";

    $result = mysql_query($query);

    if($result) {

     return 'yes';

    }     
}

It's not executing... saying the code has some fault...

Can anyone tell me what is the error in the code.

+4  A: 

I always add a statement to print the generated SQL code, and mysql_error() to see the internals when I get database errors (like the one I assume you're getting here).

acrosman
+1  A: 

Simply copying your code and running it shows no errors being thrown from the declaration (i.e. your PHP syntax is fine). Likely your error is being thrown by the mysql_query function encountering an error with the MySQL database not liking your query. Try modifying your function to be

<?php
function updateDemo($demoTitle, $desc, $keyword, $linkTitle, $clientname, $imageTitle, $adminName, $demoID)     // add new category
{   

    $query = "UPDATE demos SET demoTitle ='$demoTitle' , dmDesc = '$desc' , dmKey = '$keyword' , dmLink= '$linkTitle' , client='$clientname' , imageTitle = '$imageTitle' , userName = '$adminName' WHERE id = '$demoID'";
    $result = mysql_query($query);
    if($result) {
        return 'yes';
    } else {
        die('Invalid query: ' . mysql_error());
    }
}
?>

This will give you a (more) descriptive error if there is indeed a MySQL error causing your problem.

MidnightLightning
+2  A: 

Without knowing the specific error, my wild guess is:

WHERE id = '$demoID'

I'd guess id is an int, and you should lose the quote marks here.

Again, a wild guess until we get an error message.

Bob Kaufman
+1 - This *has* to be it... I am too slow!
John Rasch
+1  A: 

My guess would be that the error occurs here:

WHERE id = '$demoID'

I'm guessing demoID is an int, so you want:

WHERE id = $demoID
John Rasch
+1 for inferring a reasonable solution!
Bob Kaufman
A: 

probably one of those variables has some unescaped data in it and break the query.

Mihai Secasiu
A: 

Are you escaping the variables? If not the variables may contain characters that change the SQL statement. This leaves you vulnerable to SQL Injection Attacks. See mysql-real-escape-string

Glass Robot
A: 

The answer is:

42

hobodave