SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Updating boolean in mysql with php query

    Hi,

    I have created a new boolean column on my table and I want to update it when I have viewed the contents of a row.
    So I have made a page where I can view the contents of a row where id = whatever. And I made the function below to update the boolean value and the date. But I get a warning saying missing argument 1 for my function.
    Toi be honest I have never used booleans in mysql before, so I might be doing this completely wrong.

    In the table, I have a row called leads and the boolean column is called sent which has a default value of 0. Here is my function, which I simply call when the view page is launched.

    PHP Code:
    // Mark Sent
    function mark_sent($params)

          
    $id $_GET['id']; 
          
    $connection db_connect();        
          
    $query = ("UPDATE leads SET sent = '1', date = 'NOW()' WHERE id = '$id'" );        
          
    $result mysql_query($query);
            if (!
    $result)
            {
              return 
    false;
            }
            else
            {
              return 
    true;
            }        
        } 

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    function mark_sent($params)

    This function is expecting input in the form of a single parameter $params. If you are calling it as mark_sent(), you arnt sending anything through to fill $params, hence the error. You can remove the $params from the function definition, since you dont actually appear to be using it in the function.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Duh! Thanks StarLion!

    I copied & edited an existing function which originally had sprintf stuff in it, another rookie mistake. Works a treat now, many thanks

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,274
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by BuddyH View Post
    And I made the function below to update the boolean value and the date.
    you are updating the column to a string, not a datetime value

    i'll bet you actually want to use the NOW() mysql function, instead of the string 'NOW()'

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha yes that was going to be my very next puzzle, you beat me to it!
    Thanks guys, you rock!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •