Ashok Kumar Reddy S
Ashok Kumar Reddy S

Reputation: 105

MySql Php Update is not working?

I am facing some issue with update in Mysql Php..

Here is the code I am using

    $email = $_REQUEST['email'];
    $name  = $_REQUEST['name'];
    $char ='this is chara'; //$_REQUEST['character'];
    $des  = $_REQUEST['des'];
    $id = $_REQUEST['id'];

$sql_update = "UPDATE cast SET name ='".$name."',Gendor ='".$email."', character = \'ashokkumar2\',description ='".$des."' WHERE id = '".$id."'";
$result=mysql_query( $sql_update);
if ($result){
    echo 1;
}

Upvotes: 0

Views: 89

Answers (3)

Thomas Potaire
Thomas Potaire

Reputation: 6256

First of all, do not use mysql_* functions instead use PDO because your script is completely open to SQL injections.

character = \'ashokkumar2\' 

should be

`character` = 'ashokkumar2' 

character is a reserved word in MySQL so you need to escape the word with tildas. Another way to avoid issues with reserved words is to name your columns with multiple words separated by underscore such as character_name.

If you need more information print the output of mysql_error() after you run the query.

Remember, do not use mysql_* instead use PDO or MySQLi.

Upvotes: 2

Devang Rathod
Devang Rathod

Reputation: 6736

Try this

$sql_update = "UPDATE cast SET name=$name,Gendor=$email,character='$char',description=$des WHERE id = $id";
$result=mysql_query($sql_update);
if ($result){
    echo 1;
}

Upvotes: 0

Giovanni Benussi
Giovanni Benussi

Reputation: 3500

If the above answer doesn't work, can you copy and paste the output of: print $sql_update

Maybe this give us the answer more clear.

Upvotes: 0

Related Questions