Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    60
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Inserting array values into database

    This is what I have so far, does not work.

    Code:
    foreach ($this->ipn_data as $key=>$value) {
            $query    = "INSERT INTO paybox ('$key') 
                 VALUES('$value')";
    			mysql_query($query,$link);
    		 
          }
    the $link is the
    Code:
    $link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');

  • #2
    New Coder
    Join Date
    Nov 2011
    Posts
    60
    Thanks
    1
    Thanked 0 Times in 0 Posts

    So still not working

    I ended up echoing out my query

    Code:
    INSERT INTO paybox ('verify_sign') 
                 VALUES('AFsBMSMvEgrDc.j8KanEyiKNsJ8HAHog4f1AXfsZn-aaSPQAMO5xjKDU')
    I assumed that the single ticks were messing it up on the first value so I ran a str_replace, which did not remove them

    Code:
    $stunner =  str_replace( "'", " ",$key);
    So current code is

    Code:
       foreach ($this->ipn_data as $key=>$value) {
             if ($key == 'verify_sign'){
    		  $text .=  'this is the verify_sign' . $value . "\n";
    		  $stunner =  str_replace( "'", " ",$key);
    		   $query = "INSERT INTO paybox (".$stunner.") 
                 VALUES('".$value."')";
    			 $text .= 'this is query' . $query . "\n";
    			mysql_query($query,$link);
    			
    		  }
    	
    		 }

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,299
    Thanks
    57
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by dawg View Post
    This is what I have so far, does not work.

    Code:
    foreach ($this->ipn_data as $key=>$value) {
            $query    = "INSERT INTO paybox ('$key') 
                 VALUES('$value')";
    			mysql_query($query,$link);
    		 
          }
    the $link is the
    Code:
    $link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');
    We don't use quote marks ' for the column names, we use back ticks ` which are normally on the key above the tab button to the left of the 1 button.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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