-1

This query was working on mij older login script, But now that i have this new login script, my code had to change a litlle, Wich i cant seem to pull off. Im think the troubles are in the end where the if user is online is checked...

This is my code

<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();

if(!$user_home->is_logged_in())
{
    $user_home->redirect('index.php');
}

$stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
?>

<?php
    function pay_credits() {
    mysqli_query("UPDATE `tbl_users` SET `credits`=`credits`-'1' WHERE `watching`='1' AND `credits`>'0' AND userID=:uid");
    } 
?>

<?php
    pay_credits();
?>

The top script is working fine, But the function pay_credits doesnt work, Ive tried changing mysql to mysqli as i hear alot over that it has deprecated and stuff, But still no result, Ive also been reading about pdo but i have no knowledge of this. Any help is welcome, I also like to learn so maybe you can explain what you`ve done a litlle. Thnx :)

kobar1990
  • 13
  • 8
  • these scripts cant be copy pasted, they need to be a custom fit, how on earth can you then have a duplicated lol... – kobar1990 Jan 04 '16 at 13:26

2 Answers2

0

First: if you read mysqli_query manual, you'll see that mysqli_query takes two arguments. First is link and second is a query string.

Do you see a link in your pay_credits function? Nope.

Second: I noticed that you use PDO::FETCH_ASSOC and then suddenly switch to mysqli.

PDO and mysqli are totally different APIs and you should choose which one you use.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • so what direction do i need to look, pdo that performs a query, or create a new mysqli with new database connection that injects my function? – kobar1990 Jan 04 '16 at 13:54
0

You use pay_credits() without settings, your function mysqli_query need a params for db connection.

Ende Neu
  • 15,581
  • 5
  • 57
  • 68
rdn87
  • 739
  • 5
  • 18
  • Ive also tried to include my config.php, So i therefor think msqli_query does have the params for the database connection, yet it still wont update ? And pay_credits doesnt need settings, its been included and excluded by another function, when its included it needs to stay running. – kobar1990 Jan 04 '16 at 13:52
  • What param im i missing here then, it is saying i have 1 of the 2 required... Pls i am not as advanced as you guys. – kobar1990 Jan 04 '16 at 14:52