简体   繁体   English

用php更新sql数据库

[英]Updating sql database with php

I'm really pulling my hair out with this one. 我真的用这个把头发拉了出来。 I'm trying to update my articles table. 我正在尝试更新我的文章表。

My SELECT statement works fine 我的SELECT语句工作正常

  $result = mysql_query("SELECT * FROM articles") or die(mysql_error());

But my UPDATE statemnt fails, while not throwing any mysql errors. 但我的UPDATE statemnt失败了,而没有抛出任何mysql错误。

$sql = "UPDATE articles SET kudos = 10 WHERE id = 1" ;
$query = mysqli_query($sql)or die(mysql_error());

Any and all help is appreciated! 任何和所有的帮助表示赞赏!

EDIT: I'm determining it failed with this if statement 编辑:我用这个if语句确定它失败了

if($query) {
        echo 'it worked';
    } else {
        echo 'it failed';
    }

在第一个例子中你正在使用mysql_query而在第二个例子中你正在使用mysqli_query ,你应该使用哪一个?

Your SELECT statement works with: 您的SELECT语句适用于:

$result = mysql_query("SELECT * FROM articles") or die(mysql_error());

and you're mixing both mysqli_* and mysql_* functions in: 并且你将mysqli_*mysql_*函数混合在:

(which you can't do because they are not compatible together) (你不能这样做,因为它们不兼容)

$query = mysqli_query($sql)or die(mysql_error());
      has i --^

and since your successful SELECT works with mysql_* functions, then use: 由于您的成功SELECT与mysql_*函数一起使用,因此使用:

$query = mysql_query($sql)or die(mysql_error());
      no i --^

However, you're better off using full mysqli_* functions in its entirety, since mysql_* functions are deprecated and will be removed from future releases. 但是,最好完全使用完整的mysqli_*函数,因为不推荐使用mysql_*函数,并且将从以后的版本中删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM