开发者

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.


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);


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'";


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

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜