SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I word my php update statement?

    I need to say something like the following, not sure how to do it though:

    PHP Code:
    <?php 
    mysql_query 
    (update table set lockedstatus='LOCKED' where username="all usersnames located in table");
    ?>

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So basically, you want to update ALL entries?

    In that case, you don't need where part.
    -- Jelena --

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Whistler, Canada
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    mysql_query (update table set lockedstatus='LOCKED' where username="all usersnames located in table"); 

    Mind the quotes, the query is a string:

    PHP Code:
    mysql_query("update table set lockedstatus='LOCKED'"); 
    Cheers,
    Pepe

  4. #4
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay great thanks so much. Another quick question though, I need to say something like the following:

    Select username from table where
    department = variable
    department2 = variable
    etc

  5. #5
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You know there is a mysql forum, right?

    Anyway, in that case you'd use the AND operator between the two parts of the where clause.

  6. #6
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You construct MySQL queries as normal strings, meaning you can concatenate (.) or place (properly validated) variables in a double quoted strings to construct the string dynamically.

    You then just send that string to mysql via mysql_query or mysqli_query


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
  •