Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Member
    Join Date
    Jul 2007
    Posts
    64
    Member #
    15493
    if ($userdata['user_LastManagement'] == $now){
    echo "You've already managed your turns today!";
    }else{
    $result = dbquery("UPDATE ".$db_prefix."users SET user_LastManagement= '$now', user_AvailableTurns = '$total' WHERE user_id='".$userdata['user_id']."'") or die(mysql_error());
    };
    This is my code. I'm curious as to how to echo an statement ONLY in the event that the query worked. I've tried adding it at the bottom but it says it no matter what.:devious:

  2.  

  3. #2
    Member
    Join Date
    Apr 2007
    Posts
    96
    Member #
    15165
    Quote Originally Posted by riseofthevalk
    if ($userdata['user_LastManagement'] == $now){
    echo "You've already managed your turns today!";
    }else{
    $result = dbquery("UPDATE ".$db_prefix."users SET user_LastManagement= '$now', user_AvailableTurns = '$total' WHERE user_id='".$userdata['user_id']."'") or die(mysql_error());
    };
    I have never been a big fan of
    or die()
    nor have I liked building a SQL statement right in the middle of a function. All data going into a SQL string should be sanitized. Parameterized query is even better.

    However, to answer your question.
    PHP Code:
    //assumming $db_prefix, $now, $total and $userdata is safe
    $query "UPDATE ".$db_prefix."users SET user_LastManagement= '$now', user_AvailableTurns = '$total' WHERE user_id='".$userdata['user_id']."'";

    //assumming dbquery returns same return types as mysql_query
    $result dbquery($query);
    if(
    $result)
    {
    echo 
    $query;


  4. #3
    Member
    Join Date
    Jul 2007
    Posts
    64
    Member #
    15493
    Hrm, but this doesn't take into account my other ifelse stuff. :\

  5. #4
    Member
    Join Date
    Jul 2007
    Posts
    64
    Member #
    15493
    ???

  6. #5
    Member
    Join Date
    Apr 2007
    Posts
    96
    Member #
    15165
    I can't believe I actually have to type this out...

    PHP Code:
    if ($userdata['user_LastManagement'] == $now)
    {
    echo 
    "You've already managed your turns today!";
    }
    else
    {

    //assumming $db_prefix, $now, $total and $userdata is safe
    $query "UPDATE ".$db_prefix."users SET user_LastManagement= '$now', user_AvailableTurns = '$total' WHERE user_id='".$userdata['user_id']."'";

    //assumming dbquery returns same return types as mysql_query
    $result dbquery($query);
    if(
    $result)
    {
    echo 
    $query;
    }



  7. #6
    Member
    Join Date
    Jul 2007
    Posts
    64
    Member #
    15493
    Thank you!

  8. #7
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    I recommend that you change the last instance of $query to echo something else, otherwise it'll plaster info on your database structure all over the page every time the query works.

  9. #8
    Member
    Join Date
    Jul 2007
    Posts
    64
    Member #
    15493
    No worries. I never planned on echoing the actual query.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:59 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com