www.webdeveloper.com
Results 1 to 3 of 3

Thread: populate query from variable???

  1. #1
    Join Date
    Jan 2006
    Posts
    95

    populate query from variable???

    Hi,
    Was wondering how I might go about getting a value from a variable (eg. $to_address) into a query???
    Something like
    PHP Code:
    function contact_cycle() {   
        
    $update_cycle =" update contacts set cycle=cycle+1 where $to_address  = contacts.email1;
        
    $result = $db->query($update_cycle);   

    Does that make any sense?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    Since $to_address is presumably a string (not just a number), it will need to be quoted:
    PHP Code:
    $update_cycle "UPDATE contacts SET cycle = cycle + 1 WHERE email1 = '$to_address'"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jan 2006
    Posts
    95
    Yes sir'ee BOB that does the trick! The whole thing ended up looking like
    PHP Code:
    function email_cycle_update() {   
        if(!empty(
    $_REQUEST['to_addrs'])) {
            
    $to_addrs $_REQUEST['to_addrs'];
        
    $update_cycle =" update contacts set cycle=cycle+1 where email1= '$to_addrs' ";           
        
    $db = & PearDatabase::getInstance();   
        
    $result $db->query($update_cycle);   
        }} 
    but you got it right, and now I do too!
    Thank ye kindly!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles