Jump to content

dean7

Members
  • Posts

    309
  • Joined

  • Last visited

Posts posted by dean7

  1.  

    If you are storing the time as an integer timestamp then that last line of that query needs to use FROM_UNIXTIME to convert to a DATETIME type

    ... AND FROM_UNIXTIME(last_action) >= NOW() - INTERVAL 1 YEAR

    Yeah I am storing as a interger timestamp. So would this only show the users who have done something in the pass year? So users who haven't been on for 2-3-4 years won't be shown?

     

    Thanks for all your help!

  2. Hey all, I'm coding a script which gets all the money what is in the game but I'm wanting it to only show the users who have been active in the past year.

    So if you've been active your money adds on if you've not been online for a year it don't add the money on, if that makes sense?

     

    Here is my little bit of code I'm working with:

    $LastMove = mysql_query("SELECT last_action, last_login FROM users") or die(mysql_error());
    $Move = mysql_fetch_object($LastMove);
     
    $Movement = $Move->last_action;
     
     
    $newTimestamp12 = strtotime('-1 years', $Movement);
    $date3 = new DateTime("@$newTimestamp12");
    $New3 = $date3->format('Y') . "\n";
     
     $stats=mysql_query("SELECT SUM(money),COUNT(id),SUM(exp) FROM users WHERE banned = 'n' AND active = 'y' AND last_action <= '$New3'");
     
    
     
    Last_action is just time() which gets updated soon as them come online and are doing things on the site.
     
    With my code, would that only show users who have been active for the past year?
     
    Hope I've explained that well enough.
     
    Thanks for any help provided
  3. I didn't explain it very well. Let me try again,

     

    I'm coding a page to show users who haven't logged in for so many years (2,3,4,5 years etc). In my database I'm holding the last login like this: 14th Dec 16, 16:00. How would I do a query to select all the users from the year posted? 

     

    Hope this is slightly clearer

  4. Hey guys, just a quick question, I'm wanting to select all the inactive users from the database who have been inactive for like 2 years, 3 years, 4 years etc from their last login but how would I go by doing this?

     

    I mean I'm guessing you would get all the users which are < the date posted but I'm unsure how I can get the results to what I'm after?

     

    Any help is appreciated.

     

    Thanks!

  5. are your form fields within a valid post method <form></form>?

     

    is your html valid? if it's not, the form fields could be broken and not be considered by the browser to be form fields.

     

    what exact post data is being submitted?

     

    do you have php's error_reporting set to E_ALL and display_errors set to ON (in the php.ini on your development system) so that php would help you by reporting and displaying all the errors it detects?

     

    is the posted code the complete file? it's missing at least two closing } that would producing a php syntax error.

     

    lastly, in addition to the questionable statements and logic being used, to provide an audit-trail for the transactions, which also helps in debugging program operation, you should not just add/subtract amounts in a database table field. you should store each plus or minus transaction as a row in a table. to get the current total, you would just SUM() up the values for any user.

     

    Yeah I have the <form></form> tags around the table just not shown in that piece of code, and no its not the full lot its just the bidding side of things piece of code as the rest works to how I like it. It should be submitting the value of whats in the text box but when clicking it just flashes my page and does nothing

  6. Hey all, I'm coding a auction page for my website which allows users to bid on certain items without leaving the page, but what I'm getting is when you put your amount in then press the submit putting it returns nothing, this is what I have:

     

    This shows the auctions to bid on

    echo '<tr>
     <td width="20%" bgcolor="#707070 ">'.htmlspecialchars($Market->carforsale).'</td>
     <td width="10%" bgcolor="#707070"><a href="Market.php?viewcar='.htmlspecialchars($Market->carid).'" target="mainFrame">View Car Stats</a></td>
     <td width="15%" bgcolor="#707070">£'.htmlspecialchars(number_format($Market->price)).'</td>
     <td width="15%" bgcolor="#707070"><a href="profile.php?view='.htmlspecialchars($TheBidderIs).'" target="mainFrame">'.htmlspecialchars($TheBidderIs).'</a></td>
     <td align="center" width="15%" bgcolor="#707070">£<input name="MakeBid" type="text" id="MakeBid" value="'.htmlspecialchars($price).'" class="textinput"><input name="BidCar" type="submit" id="BidCar" class="button" value="Make Bid"></td>
     <td width="15%" bgcolor="#707070">'.htmlspecialchars(MakeTimeLeft($Market->timeleft)).'</td>
     <td width="10%" bgcolor="#707070">'.$RemoveButton.'<input type="hidden" name="theid" value="'.htmlspecialchars($Market->id).'"></td>
     </tr>';
    

    This is the code to submit the bid. (Not actually tested as come across the issue with submitting)

    if (strip_tags($_POST['BidCar']) && strip_tags($_POST['MakeBid'])){
    
     
    
    $MakeBid = strip_tags(htmlspecialchars(trim($_POST['MakeBid'])));
    
     
    
    if ($Market->seller == $Username){
    
     
    
    echo "<br /><table class='tableborder' width='20%' cellpadding='1' cellspacing='0' border='1' align='center'>
    
    <tr>
    
    <td class='error_header' align='center'>Error</td>
    
    </tr>
    
    <tr>
    
    <td align='center'>You cannot bid on your own Auctions!</td>
    
    </tr>
    
    </table>
    
    <br />";
    
     
    
    }elseif (strlen($MakeBid < 100)){
    
     
    
    echo "<br /><table class='tableborder' width='20%' cellpadding='1' cellspacing='0' border='1' align='center'>
    
    <tr>
    
    <td class='error_header' align='center'>Error</td>
    
    </tr>
    
    <tr>
    
    <td align='center'>Your bid must be £100 or more!</td>
    
    </tr>
    
    </table>
    
    <br />";
    
     
    
    }elseif($MakeBid < $Market->price){
    
     
    
    echo "<br /><table class='tableborder' width='20%' cellpadding='1' cellspacing='0' border='1' align='center'>
    
    <tr>
    
    <td class='error_header' align='center'>Error</td>
    
    </tr>
    
    <tr>
    
    <td align='center'>Your bid must be more than ".htmlspecialchars(number_format($Market->price))."!</td>
    
    </tr>
    
    </table>
    
    <br />";
    
     
    
    }elseif($MakeBid > $UsersTable1->money){
    
     
    
    echo "<br /><table class='tableborder' width='20%' cellpadding='1' cellspacing='0' border='1' align='center'>
    
    <tr>
    
    <td class='error_header' align='center'>Error</td>
    
    </tr>
    
    <tr>
    
    <td align='center'>You don't have enough money to bid!</td>
    
    </tr>
    
    </table>
    
    <br />";
    
     
    
    }else{
    
     
    
    // Update Bidded - Give money back to outbidder if is a outbidder - Send message to Outbidder
    
     
    
    $BidderMoney = $UsersTable1->money;
    
    $NewMoneyBidder = $BidderMoney - $MakeBid;
    
     
    
    $BidderNewMoney = $db->prepare("UPDATE `UsersRegTable` SET money = :money WHERE username = :username");
    
    $BidderNewMoney->bindValue(':money', $NewMoneyBidder);
    
    $BidderNewMoney->bindValue(':username', $Username);
    
    $BidderNewMoney->execute();
    
     
    
    $UpdateBidMarket = $db->prepare("UPDATE `market` SET bidder = :bidder, price = :price WHERE id = :marketid");
    
    $UpdateBidMarket->bindValue(':bidder', $Username);
    
    $UpdateBidMarket->bindValue(':price', $MakeBid);
    
    $UpdateBidMarket->bindValue(':marketid', $Market->id);
    
    $UpdateBidMarket->execute();
    
     
    
    echo "<br /><table class='tableborder' width='20%' cellpadding='1' cellspacing='0' border='1' align='center'>
    
    <tr>
    
    <td class='header' align='center'>Success</td>
    
    </tr>
    
    <tr>
    
    <td align='center'>You have successfully bidded for that car!</td>
    
    </tr>
    
    </table>
    
    <br />";
    

    I'm not sure why its not subbmitting any data? its also not giving me any errors saying why in my code and nothing in the error log.

     

    Thank you for any help given

  7. Hey guys I've got this script which I've been coding which allows users to stock cars.. I've been testing it as I code it in which all the error messages display at the right time work on hitting submit but when it comes to the time to update the database it just refreshes the page and don't do anything. I cannot work out the reason why?

    elseif (is_numeric($BuyCars)){
     
    // Form has value, form is ALSO a number
     
    // Now get cost of the car to stock and how many they want
     
    // $Stocked is CarName 
     
    $CarInfo = $db->prepare("SELECT * FROM `cars` WHERE carname = :carname");
    $CarInfo->bindParam(":carname", $Stocked);
    $CarInfo->execute();
    $CarReal = $CarInfo->rowCount();
     
     
     
    $GetTheStockNow = $db->prepare("SELECT * FROM `Dealercars` WHERE location = :location AND carname = :carname");
    $GetTheStockNow->bindParam(":location", $DeLoc);
    $GetTheStockNow->bindParam(":carname", $Stocked);
    $GetTheStockNow->execute();
    $GetTheThe = $GetTheStockNow->fetchObject();
     
    if ($CarReal != "1"){
     
    echo "Failed finding car";
     
    }elseif ($CarReal >= "1"){
     
    // Car Found
     
    $OldCarStats = $CarInfo->fetchObject(); 
     
    $BuyPrice = $OldCarStats->value; // Value of Car from defult value
     
    $CostOfBuy = $BuyPrice * $BuyCars; // Cost of stock
     
    $Money = $UsersTable1->money; // $Usernames money
     
    // Has the $Username got enough money to buy the stock?
     
    if ($UsersTable1->money < $CostOfBuy){
     
    echo "You dont have enough money to buy this amount of stock!";
     
    }elseif ($UsersTable1->money >= $CostOfBuy){ 
     
    $StuffStock = $GetTheThe->stock;
     
    $NewMoney = $Money - $CostOfBuy; // Money after buying stock
     
    $NewStock = $StuffStock + $BuyCars; // The New Stock
     
     
    // Take the money from user for buying stock 
    $TakeMoneyAway = $db->prepare("UPDATE `UsersRegTable` SET money = :money WHERE username = :username");
    $TakeMoneyAway->bindValue(':money', $NewMoney);
    $TakeMoneyAway->bindValue(':username', $Username);
    $TakeMoneyAway->execute();
     
    // Update thier car dealership with the stock they just brought
     
    $UpdateStock = $db->prepare("UPDATE `Dealercars` SET stock = :stock WHERE location = :location AND carname = :carname");
    $UpdateStock->bindValue(':stock', $NewStock);
    $UpdateStock->bindValue(':carname', $Stocked);
    $UpdateStock->bindValue(':location', $DeLoc);
    $UpdateStock->execute(); 
     
     
    echo "You successfully brought ".htmlspecialchars(number_format($BuyCars))." for £ ".htmlspecialchars(number_format($CostOfBuy))."";
     
     
       }
    

    Am I missing something very obvious here ?

     

    Thanks for any help given

  8. Hey guys, I'm currently coding a forum for my site which is just being made for a time waster and to see what I can actually do but in the forum I'm trying to make it so certain forum topics show at the top of the table, for example, Id want Important topics, then Sticky topics the basic topics;

     

    Important: Test

    Sticky: Test

    Test

     

    That sort of format. Regardless of the last reply in the topics I want the forum to always hold that layout. So if there was 3 "Important" topics the topic with the newest reply will be on top but if there is a new reply in the normal topics I want that at the top but below Important and Sticky.

     

    I've currently got:

    if (($Topics->important == "2") AND ($Topics->locked == "2")){
     
    $TitleF =  "<strong><u>Important:</u></strong> <a href='Right.php?topicid=$Topics->id' target='frameright'>".check($Topics->topicname)."</a> (Locked)";
     
    }elseif (($Topics->important == "2") AND ($Topics->locked == "1")){
     
    $TitleF =  "<strong><u>Important:</u></strong> <a href='Right.php?topicid=$Topics->id' target='frameright'>".check($Topics->topicname)."</a>";
     
    }else{
     
    $TitleF =  "<a href='Right.php?topicid=$Topics->id' target='frameright'>".check($Topics->topicname)."</a>";
     
    }
    

    Further down my code to try to display the topics how I want I tried this:

    $Important = $Topics->important;
    $Sticky = $Topics->sticky;
     
    if ($Important == "2"){
     
    $Top = $TitleF;
     
    }elseif ($Sticky == "2"){
     
    $Middle = $TitleF;
     
    }else{
     
    $Bottom = $TitleF;
     
    }
     
    echo "".$Top."".$Middle."".$Bottom."
    </td>
    </tr>"; 
    
     
    All that seems todo is just display the topics but completely wrong.
     
    Is there another way I should be going around this?
     
    Thanks!
  9. You forgot the HTML-escaping. Dynamic values which are inserted into an HTML context must be escaped. Don't just assume that they're safe.

     

     

     

     

    I don't think you understand the structure of $_POST['select_car']. It's an associative array with the car ID as the key and the car value as the corresponding value:

    ID => car value
    

    Right now, you're trying to use the car value as the ID, which doesn't make sense. The ID is the key:

    foreach ($_POST['select_car'] as $car_id => $car_value)
    {
    
    }
    

    Also, don't forget about the CSRF vulnerability.

    Yes thank you , thats what I was aiming for as I wanted to check the value of the car is the same from in the database. As $car_value is holding each value of the selected cars how would I add all the selected car values up? I've read something about array_merge or could I just do sum($car_value)?

     

    Thanks

  10. So would this be how you mean for the form?

     

     

    <input id="select_car" name="select_car['.$CarID.']" type="checkbox" value="'.$CarValue.'" onclick="CountCheck()" />
    

     

    The for the PHP bit:

     

     

    if (isset($_POST['sell_selected'])){
     
    $PostValues = $_POST['select_car'];
     
    foreach($PostValues as $value) {
     
    $GetInfo = $db->prepare("SELECT * FROM garage WHERE id = :id");
    $GetInfo->bindParam(":id", $value);
    $GetInfo->execute();
    $CarInformation = $GetInfo->fetchObject(); 
     
     
    } 
    }
    

    When I try getting the information from the database it says: Notice: Trying to get property of non-object even thought the obj should be fine as I'm getting the ID from the checkbox?

  11. Hey guys, I've got problem which seems it should be so simple to resolve but I just can't put it together . I'm needing to show all of the values of the Check Boxes clicked when I hit submit,

     

    I have this:

    echo ('<tr><td><input id="select_car" name="select_car[]" type="checkbox" value="'.$CarID.'"" onclick="CountCheck()" /><a href="?getin='.$CarID.'">'.$CarName.'</a> ('.$CarIDCol.')</td><td><a href="?repair='.$CarID.'">'.$CarDamage.'%</a></td><td><a OnClick="javascript: return confirm(\'Are you sure you want to sell?\');" href="?sell='.$CarID.'">£'.number_format($CarValue).'</a><input type="hidden" name="values[]" id="values[]" value="'.$CarValue.'"></td><td><a href="?stats='.$CarID.'">View Stats</a></td></tr>');
    

    In my form:

    <input name="sell_selected" type="submit" id="sell_selected" value="Sell Selected" class="button" onClick="JavaScript:return confirm('Are you sure you want to sell?');" />
    
    if (!empty($_POST['sell_selected'])){
     
    foreach ($_POST['values'] as $value){
     
    echo $value;
    }
    }
    
     
    With my code its displaying all the values of even the ones which haven't been checked? 
    How can I make it so it only shows the values of the checked checkboxes?
     
    Only needing that as once I can see them values I need to add them together to give the final figure of the extra money of all things sold
     
    Thanks for any help
  12. Yeah sorry its hard explaining what I want to achieve.

     

    Its dont matter what this week would start as. If this week is week one, next week would need to be week two, or the other way around. Week to start Sunday and end Saturday, so like Saturday at midnight it would change to the next week

  13. Hey guys I'm trying to code some code which gives me a week 1 or a week 2. So for example, this week is week one, next week is week two the following week after would be week one again.

     

    How can I actually code this? 

     

    Would it be an ideal way to maybe get the week number and if the week number is Even its Week 1 if its Odd its Week 2? or is there a simple way I could go about this?

     

    Thanks for any advice!

  14. Hey all I've got a simple problem of what I believe but its becoming a pain, I'm simply selecting a time from the database which is inputted in then I want to display it in Minutes and seconds;

     

    This is what I have. I should display the time I have left as I have got time left to wait although its always showing I'm free?

     

    Any reason behind this?

     

    Thanks for any help!

    if ($UsersTable1->action1time  > time()){
    $left = $UsersTable1->action1time  - time();
     
    $mins = floor($left / 60); // number of whole minutes left
    $secs = sprintf('%02d', $left % 60); // remainder of time left (in seconds) divided by 60.
     
    $Time = "$mins min and $secs secs";
     
    }else{
    $Time = "Free!";
    }
    
  15. Well, you can pretty much guarantee all your other script is irreverent until you fix this.  How are you getting to this page?  A GET or POST request?  PHP is a little funny in that it populates the $_GET super even upon a POST request if the URL contains parameters.

    I'm getting it through a $_GET and everything else on my script is actually working as it don't all rely on this $_GET. A few posts up is what I'm trying to fix

  16. Thanks, I can add that on :) I generally do escape it all.

     

    On another note, I'm also wanting to bring over a messageid which is the same I had with the other get value but with the message ID i'm wanting to perform a query which lets me select things from that message from the database. But when I do $_GET['messageid']; its not giving me the ID?

    $messageid = $_GET['messageid'];
    echo $messageid; // does it show an id
     
    $InboxStuff = $db->prepare("SELECT * FROM `inbox` WHERE `id` = :id");
    $InboxStuff->bindParam(":id", $messageid);
    $InboxStuff->execute();
    $IbxObj = $InboxStuff->fetchObject();
    
    if ($_GET['messageid']){ 
     
    echo '<textarea class="textinput" name="text" cols="75" cols="75" rows="10" id="text">[b]Last said:[/b] 
    $message</textarea>'; 
     
    }else{
     
    echo '<textarea class="textinput" name="text" cols="75" rows="10" id="text"></textarea>'; 
     
    }
    
  17. Hey all, I'm coding a Private message system for my website which obviously allows users to message each other.

     

    On my Inbox script I have a link which when clicked goes to my send message script what should then have the username in the username box already.

     

    For example:

     

    inbox link to message other users:

     

    SendMessage.php?touser=**The username** 

     

    Now on the send message form the Username should be filled with the users username what is clicked.

     

    I'm using $_GET['touser']; to pull over the username but its not adding it into the box?

     

    The inbox show message part which contains the link:

    echo ("<table width='50%' align='center' class='tableborder' border='1' cellpadding='0' cellspacing='0'><tr><td class='header' align='center'>$message->subject</td></tr><tr><td class='Tablebottom' align='center'>From: <a href='profile.php?view=$message->from' >$message->from<a/> | <a href='SendMessage.php?touser=$message->from'>Reply</a> | Date: $message->date</a></td></tr><tr><td>" .clean($message->message). "</td></tr></table> <br />"); 

     
     
    Part of the send message script
     
    $ToUser = $_GET['touser'];
     
    
    <td width="50%"><div align="right">To:</div></td>
    <td width="50%"><div align="center">
    <input name="to" type="text" class="textinput"  id="to" value="<?php $ToUser; ?>"  maxlength="20" size="38"></div></td>
    </tr>
    
    

    The username should only appear in the box if a username is clicked on the message else it should be blank for you to input a name but its always showing blank. If i echo out $ToUser it does show the username just not in the box? 

     

    Thanks for any help given :)

     

×
×
  • 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.