SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: MYsql Issue

  1. #1
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MYsql Issue

    i have the following code

    PHP Code:
        // Process your response here
        
    $jsonData json_decode($response);

    if (
    $jsonData->status === 'success') {
        
        
    // Grab Message ID
        
    foreach($jsonData->messages as $txtid)
      {
       
    // Got Message ID
       // Success code
        
    echo ('Sent: message to '.$to.' appearing to be sent from '.$from.' <br><br> One Credit used.<br><br>');
      }  
        
      


    // Insert Details to log 
        
    $sth2 $db->prepare ("INSERT INTO logs (id,`to`,`from`,message,`txtid`) VALUES (:id,:to,:from,:message,:txtid)"); 
        
    $sth2->bindParam(':id'$idPDO::PARAM_INT); 
        
    $sth2->bindParam(':to'$toPDO::PARAM_INT); 
        
    $sth2->bindParam(':from'$fromPDO::PARAM_INT);
        
    $sth2->bindParam(':message'$messagePDO::PARAM_STR);
        
    $sth2->bindParam(':txtid'$txtidPDO::PARAM_STR);
        
    $sth2->execute(); 
    and i am getting the following error
    Code:
    Catchable fatal error: Object of class stdClass could not be converted to string in
    i have tried txtid as PARAM_INIT and STR

    the database is set to varchar and it the txtid will be numbers

  2. #2
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i did a var dump and get the following
    Code:
    object(stdClass)#5 (2) { ["id"]=> string(10) "1163196774" ["recipient"]=> int(447777777777) }

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    a var dump of what?

  4. #4
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $txtid i thought this would be the best to dump to see if this could help

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    So $txtid doesn't contain an id, but an object.
    Maybe (just a guess because I don't know the meaning of the data you're working with) you should use $txtid->id ?

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    88
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Just a guess, but you are binding the "to" and "from" values as Integers, when I would think they s/b strings. Could that be the issue?

  7. #7
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    So $txtid doesn't contain an id, but an object.
    Maybe (just a guess because I don't know the meaning of the data you're working with) you should use $txtid->id ?
    i changed
    PHP Code:
    $sth2->bindParam(':txtid'$txtidPDO::PARAM_STR); 
    to

    PHP Code:
    $sth2->bindParam(':txtid'$txtid->idPDO::PARAM_STR); 
    and this has worked wonders thank you very much!


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
  •