1

This makes no sense to me?..

Ok so i have an SQL query that i am doing like this

$wut = new mysqli("1", "2", "3", "4");
$updateReferralPoints = $wut->prepare("UPDATE `referrals` SET `totalreferrals` = ? WHERE `referralkey` = ?");
$updateReferralPoints->bind_param("ss", $referralPointAmount,$referralKeyForUpdate);
$referralPointAmount = 10;
$referralKeyForUpdate = "1234";
$updateReferralPoints->execute();

It works completly fine...

BUT

When i add it to a function the SQL query just doesn't work..

So for example this will NOT work

if($doUpdate)
{
    updateReferralPointsCall();//DOESN'T WORK?
}

function updateReferralPointsCall()
{
    $wut = new mysqli("1", "2", "3", "4");
    $updateReferralPoints = $wut->prepare("UPDATE `referrals` SET `totalreferrals` = ? WHERE `referralkey` = ?");
    $updateReferralPoints->bind_param("ss", $referralPointAmount,$referralKeyForUpdate);
    $referralPointAmount = 10;
    $referralKeyForUpdate = "1234";
    $updateReferralPoints->execute();
}

BUT this will work

if($doUpdate)
{
    $wut = new mysqli("1", "2", "3", "4");
    $updateReferralPoints = $wut->prepare("UPDATE `referrals` SET `totalreferrals` = ? WHERE `referralkey` = ?");
    $updateReferralPoints->bind_param("ss", $referralPointAmount,$referralKeyForUpdate);
    $referralPointAmount = 10;
    $referralKeyForUpdate = "1234";
    $updateReferralPoints->execute();
}
coddding
  • 333
  • 1
  • 6
  • 15

1 Answers1

0

You need to pass the mysqli object into the function. You can only call global variables inside normal functions like this.

So, something like this should work:

if($doUpdate)
{
    updateReferralPoints($mysqlconnection);//DOESN'T WORK?
}

function updateReferralPoints($updateReferralPoints)
{