Hadi
Hadi

Reputation: 1212

Need Help with Update statement in SQl

I'm new to sql database. I'm using the update statement to modify a value in my column. All my columns are of type char, but I'm not able to modify the column. Please point out what mistake I'm making

if ($info['Patient'] === '' )
{
    UPDATE guestbook SET Message = 'howdy' WHERE Name = 'mathilda';

    $sql = "INSERT INTO guestbook(Name)VALUES('$patient')";

    $result=mysql_query($sql);

    //check if query successful
    if($result){
        echo "Successful";
        echo "<BR />";
    }
    else {
        echo "ERROR";
    }

The rest of the code is working fine and the Insert statement is working good whereas I c an't get the update statement to modify the table.

Upvotes: 1

Views: 147

Answers (4)

Gaurav
Gaurav

Reputation: 28755

$sql = " UPDATE guestbook SET Message = 'howdy' WHERE Name = 'mathilda' ";
if(mysql_query($sql)){
   // true
}

Upvotes: 1

65Fbef05
65Fbef05

Reputation: 4522

You need to use mysql_query() for your update statement as well...

$update = "UPDATE guestbook SET Message = 'howdy' WHERE Name = 'mathilda'";
mysql_query($update);

Upvotes: 1

stealthyninja
stealthyninja

Reputation: 10371

Replace

UPDATE guestbook SET Message = 'howdy' WHERE Name = 'mathilda';

$sql = "INSERT INTO guestbook(Name)VALUES('$patient')";

with

$sql = "UPDATE guestbook SET Message = 'howdy' WHERE Name = 'mathilda'";

Upvotes: 3

Michael Minton
Michael Minton

Reputation: 4495

Since you appear to be calling this from PHP you need to use the mysql_query method to execute the update statement like so:

$sql = "UPDATE guestbook SET Message = 'howdy' WHERE Name = 'mathilda'";
mysql_query($sql);

Upvotes: 4

Related Questions