Jump to content

jacob21

Members
  • Posts

    24
  • Joined

  • Last visited

jacob21's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. $query = 'SELECT pts.cashReward, pts.pointsReward, ( SELECT COUNT(ip.id) FROM ignored_pts AS ip WHERE ip.user = :username AND ip.ptsId = :id ) AS iptsCount FROM pts WHERE pts.signupsAvailable > 0 AND pts.status = "active" AND pts.id = :id2'; $select = $db->prepare($query); $select->bindParam(':id', $id, PDO::PARAM_INT); $select->bindValue(':username', $userInfo['username'], PDO::PARAM_STR); $select->bindParam(':id2', $id, PDO::PARAM_INT); $select->execute(); THIS IS REAL WORKING QUERY. Previous query does not work unless ju have on row on ignored_pts table
  2. $query = 'SELECT pts.cashReward, pts.pointsReward, SUM(CASE WHEN ip.user = :username AND ip.ptsId = :id THEN 1 ELSE 0 END) AS iptsCount FROM pts INNER JOIN ignored_pts AS ip ON pts.id = ip.ptsId WHERE pts.signupsAvailable > 0 AND pts.status = "active" AND pts.id = :id2'; $select = $db->prepare($query); $select->bindParam(':id', $id, PDO::PARAM_INT); $select->bindValue(':username', $userInfo['username'], PDO::PARAM_STR); $select->bindParam(':id2', $id, PDO::PARAM_INT); $select->execute(); WORKING QUERY
  3. $query = 'SELECT cashReward, pointsReward FROM pts WHERE signupsAvailable > 0 AND status = "active" AND id = :id'; $select = $db->prepare($query); $select->bindParam(':id', $id, PDO::PARAM_INT); $select->execute(); $rowCount = $select->rowCount(); $queryC = 'SELECT COUNT(id) FROM ignored_pts WHERE user = :username AND ptsId = :id'; $selectC = $db->prepare($queryC); $selectC->bindParam(':username', $userInfo['username'], PDO::PARAM_INT); $selectC->bindParam(':id', $id, PDO::PARAM_INT); $selectC->execute(); $count = $selectC->fetch(PDO::FETCH_COLUMN);// THIS COUNT TO FIRST QUERY Something like this $query = 'SELECT pts.cashReward, pts.pointsReward, COUNT(if(ip.user = :username and ip.id = :id, 1, 0)) AS iptsCount FROM pts INNER JOIN ignored_pts AS ip ON pts.id = ip.ptsId WHERE pts.signupsAvailable > 0 AND pts.status = "active" AND pts.id = :id';
  4. Is it possible to do this with one query? Tried with union and join but no luck. <?php $query = 'SELECT cashReward, pointsReward FROM pts WHERE signupsAvailable > 0 AND status = "active" AND id = :id'; $select = $db->prepare($query); $select->bindParam(':id', $id, PDO::PARAM_INT); $select->execute(); $rowCount = $select->rowCount(); $queryC = 'SELECT COUNT(id) FROM ignored_pts WHERE user = :username AND ptsId = :id'; $selectC = $db->prepare($queryC); $selectC->bindParam(':username', $userInfo['username'], PDO::PARAM_INT); $selectC->bindParam(':id', $id, PDO::PARAM_INT); $selectC->execute(); $count = $selectC->fetch(PDO::FETCH_COLUMN); if($rowCount == 1){// PTS // $row = $select->fetch(PDO::FETCH_ASSOC); if($count == 0){// IGNORED PTS // // ...................... // // INSERT INTO ignored_pts TABLE $row['cashReward'], $row['pointsReward']// // ...................... // print 'PTS IGNORED'; }else{ print 'You have already ignored this PTS!'; } }else{ print 'An invalid PTS was provided!'; } $db = NULL; ?>
  5. Is it a good practice to store error and success messages in SESSION? Folder pages/giftCards ->index.php ->viewGiftCardCodes.php ->redeemGiftCard.php ->giftCards.php index.php <?php if(defined('script') === FALSE){ exit('Hacking attempt...'); } if(loginCheck($userInfo) === FALSE){ redirect('index.php?do=login&returnUrl='.$_SERVER['REQUEST_URI'], FALSE, TRUE); } if($configs['giftCardEnabled'] == 'no'){ alert('This page is currently disabled.', 'index.php?do=home'); } $action = isset($_GET['action']) ? $_GET['action'] : ''; switch($action){ case 'redeemGiftCard'; include 'pages/giftCards/redeemGiftCard.php'; break; case 'viewGiftCardCodes'; include 'pages/giftCards/viewGiftCardCodes.php'; break; default: include 'pages/giftCards/giftCards.php'; break; } ?> Default action giftCards REDEEM BUTTON ................. <?php $action = '<input type="button" value="Redeem" onclick="location.href=\'index.php?do=giftCards&action=redeemGiftCard&id='.$row['id'].'&currency='.$row['currency'].'&amount='.$row['amount'].'&csrfKey='.$csrf->csrfKey().'&csrfToken='.$csrf->csrfToken().'\'">'; ?> ................. Action redeemGiftCard ................. If success <?php $_SESSION['message']['1'] = 'You have successfully redeemed a gift card worth '.$row['currency'].$row['amount'].''; redirect('index.php?do=testPage1', FALSE, TRUE);// Page, Refresh, Exit // ?> If error <?php $_SESSION['message']['2'] = 'Database error. Please try again later!'; redirect('index.php?do=testPage1', FALSE, TRUE);// Page, Refresh, Exit // ?> ................. Default action giftCards ................. <?php if(!empty($_SESSION['message']['1'])){ $success = $_SESSION['message']['1']; unset($_SESSION['message']); } if(!empty($_SESSION['message']['2'])){ $error = $_SESSION['message']['2']; unset($_SESSION['message']); } if(!empty($success)){ print success($success);// HTML and success var // } if(!empty($error)){ print error($error);// HTML and error var // } ?> .................
  6. How to remember ref and ref_id and print out detected values? I need to refresh page to get cookie value if i use this code if(!empty($_GET['ref'])){ setcookie('ref', $_GET['ref'], time() + 60 * 60 * 24 * 3); } print $_COOKIE['ref']
  7. <?php // define variables with the value for each field // the value from POST,GET if this exist, or an empty value $errors = array(); $username = isset($_POST['username']) ? filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING) : ''; $ref_id = isset($_GET['ref_id']) ? filter_input(INPUT_GET, 'ref_id', FILTER_SANITIZE_STRING) : ''; $ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : ''; if(!empty($_POST['submit'])){ if(empty($username)){ $errors[] = 'Empty username!'; } if(userIdExists($ref_id, $db) === FALSE){ $errors[] = 'User id wont exist'; } if(usernameExists($ref, $db) === FALSE){ $errors[] = 'referrer wont exist'; } } if(!empty($_POST['submit']) and empty($errors)){ print' username = '.$username.'<br>Ref = '.$ref.'<br>Ref_id = '.$ref_id.' '; } if(!empty($errors)){ foreach($errors as $error){ print $error.'<br>'; } } print ' <form method="POST"> <table style="width:100%"> <tr> <td style="width:30%;font-weight:bold">Username</td> <td style="width:70%"><input type="text" name="username" maxlength="255" style="width:200px" value="'.$username.'"></td> </tr>'; if(!empty($_GET['ref_id'])){ print ' <tr> <td style="font-weight:bold">Referred by user id #</td> <td><input type="text" name="ref_id" maxlength="255" style="width:200px" value="'.$ref_id.'"></td> </tr>'; }else{ print ' <tr> <td style="font-weight:bold">Referred by</td> <td><input type="text" name="ref" maxlength="255" style="width:200px" value="'.$ref.'"></td> </tr>'; } print ' <tr> <td colspan="2" style="text-align:center"><input type="submit" name="submit" value="Submit"></td> </tr> </table> </form>'; ?>
  8. I have 2 referring url. USERNAME http://testsite.com/index.php?do=register&ref=test USER ID http://testsite.com/index.php?do=register&ref_id=1 1. Code to remember ref and ref_id 2. Code to allow user to insert own referrer if no ref link detected? 3. Store ref and ref_id into same column Like db referrer = username/user_id or referrer = username / referrer_id = user_id ? PHP $ref_id = isset($_GET['ref_id']) ? filter_input(INPUT_GET, 'ref_id', FILTER_SANITIZE_STRING) : ''); $ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : ''); FORM if(!empty($_GET['ref_id'])){ print ' <tr> <td style="font-weight:bold">Referred by user id #</td> <td><input type="text" name="ref_id" maxlength="255" style="width:200px" value="'.cleanOutput($ref_id).'"></td> </tr>'; }else{ print ' <tr> <td style="font-weight:bold">Referred by</td> <td><input type="text" name="ref" maxlength="255" style="width:200px" value="'.cleanOutput($ref).'"></td> </tr>'; } 2. $ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : (isset($_POST['ref']) ? filter_input(INPUT_POST, 'ref', FILTER_SANITIZE_STRING) : '');
  9. It works only when input text contains url
  10. Code what i made so far. $inputText = 'This is testing http://www.youtube.com'; $allowedDomains = 'www.google.com youtube.com/ http://www.test.org'; $array = preg_split('/[\s]+/', $allowedDomains); $regex = '';//Need this line if(preg_match($regex, $inputText)){ print 'Domain match!'; }else{ print 'Domain not match!'; }
  11. I have included language file and function file in my index.php include 'includes/functions.php'; include 'languages/english.php'; english.php contains <?php $lang['success']['a'] = 'Settings have been updated.'; $lang['error']['b'] = 'Database error. Please try again later!'; ................................. ?> functions.php <?php function testFunction($id, $settings, $db){ $query = 'UPDATE table_name SET a = a + :a WHERE id = :id'; $update = $db->prepare($query); $update->bindParam(':a', $settings['a'], PDO::PARAM_INT); $update->bindParam(':id', $id, PDO::PARAM_INT); $success = $update->execute(); if($success){ print $lang['success']['a']; }else{ print $lang['error']['b']; } } ................................................. ?> Now if i print testFunction(); i got Undefined variable: lang in ............. If i include 'languages/english.php'; in testFunction() then everything works. Any other way to make $lang working without including language file in testFunction(). (Sorry for my bad english) print testfunction(2, $settings, $db);
  12. Anyone who dosen't follow shoutbox rules will be banned and admin and moderator can unban those users.
  13. How do i display unban feature based on your example? Earlier i have this if i used 2 query. if($usersRow['username'] == $sbRow['username']){ $hiddenAction .= " <a href=\"javascript:;\" onClick=\"unBan('".$sbRow['username']."')\" class=\"shoutBoxBan\" title=\"Unban\">u</a>"; }else{ ................................................
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.