通过减去一个多重数字来更新查询

时间:2015-06-29 13:39:10

标签: php mysql

我正在制作付费点击网站并且我试图让用户购买一些广告包,他们输入观看次数和每次观看费用,然后当他们提交时,它应该减去(观点)* (每次观看费用) 对不起,我的英语不好 :/ 这是我的代码:

<?php


session_start();

require_once '../uses_constants/initSite.php';

require_once '../uses_constants/class.DatabaseConstants.php';
require_once '../uses_classes/class.DBase.php';

$db = new DatabaseConstants();
$dBase = new DBase($db->getHost(), $db->getUser(), $db->getPass());
$dBase->setDatabaseName($db->getDb());

if(!$dBase->connectDatabase()){
    die('SQL ERROR at db class vd fn');
}
            $userQuery = mysqli_query($dBase->getDbobj(), "SELECT * FROM members WHERE username=\"".$_SESSION['username']."\"");
    if(mysqli_num_rows($userQuery)){
        $userData = mysqli_fetch_assoc($userQuery);
    }else{
        die('User Not Found!');
    }
if(isset($_POST['submit'])){

 $adquery = 'INSERT INTO ads (Title,Link,ViewLimit,Pays) VALUES ("'.$_POST['title'].'","'.$_POST['link'].'","'.$_POST['views'].'","'.$_POST['pays'].'")';
    mysqli_query($dBase->getDbobj(), $adquery);
    if(!mysqli_affected_rows($dBase->getDbobj())<1){
        $done = true;
    }
           $id = 0;
    $qryE = mysqli_query($dBase->getDbobj(), 'SELECT Id FROM ads');
    while($dataE = mysqli_fetch_assoc($qryE)){
        $id = $dataE['Id'];
    }

    $userQueryE = mysqli_query($dBase->getDbobj(),'SELECT id FROM members');
    while($userDataE = mysqli_fetch_assoc($userQueryE)){
        mysqli_query($dBase->getDbobj(), 'INSERT INTO view (MemberId,AdId) VALUES ("'.$userDataE['id'].'","'.$id.'")');
    }
    $userquery = 'UPDATE members SET balance=".($userData['balance']-($_POST['views'] * $_POST['pays'])" ';
    mysqli_query($dBase->getDbobj(), $userquery);




}

0 个答案:

没有答案