0

I'm really pulling my hair out with this one. I'm trying to update my articles table.

My SELECT statement works fine

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

But my UPDATE statemnt fails, while not throwing any mysql errors.

$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($query) {
        echo 'it worked';
    } else {
        echo 'it failed';
    }
3
  • How are you determining that it failed? What happens when you try the query in Mysql directly Commented Feb 12, 2014 at 23:16
  • 2
    $query = mysql_query($sql)or die(mysql_error()); <=? Since your working copy uses mysql_query - mixing both functions on one line doesn't help neither. Commented Feb 12, 2014 at 23:16
  • "EDIT: I'm determining it failed with this if statement" - No Here >>> $query = mysqli_query($sql)or die(mysql_error()); Commented Feb 12, 2014 at 23:20

2 Answers 2

1

Your SELECT statement works with:

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

and you're mixing both mysqli_* and mysql_* functions in:

(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:

$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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the clarity! I'll accept your answer once it lets me. This is not the smartest I've ever felt!
You're welcome, glad I could help. Do consider though using all mysqli_* functions instead of mysql_* :) @TheGooch - They will be removed in future releases. Cheers
1

In the first example you're using mysql_query and in the second you're using mysqli_query, which one are you supposed to be using?

1 Comment

Oh for the love of God that was it! I cannot believe I missed that! Thanks for that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.