php - UPDATE statement with multidimensional $_GET -


i trying create update statement values form multidimensional $_get

  array (     [social_link] => array         (             [0] => https://www.facebook.com             [1] => https://www.twitter.com         )      [social_id] => array         (             [0] => 1             [1] => 2         )      [social_network] => array         (             [0] => facebook             [1] => twitter         )  ) 

my db table 'social' '_id , social_network, social_link' row names

sql tried

foreach ($_get $index ) { $sql = "update social set social_link= '{$index['social_link']}' _id= '{$index['social_id']}' , social_network= '{$index ['social_network']}' ";  $stmt = $conn->prepare($sql);  $stmt->execute(); } 

but not working.

this rough method of accomplishing you're trying do, believe. ensure 3 variables available before trying update.

<?php  // loop through based on number of social ids present for( $i = 0, $icount = count( $_get['social_id'] ); $i < $icount; $i++ ) {     // values of social_id, social_link, , social_network     // if they're not set, set them false     $social_id      = ( isset( $_get['social_id'][$i] )      ? $_get['social_id'][$i]      : false );     $social_link    = ( isset( $_get['social_link'][$i] )    ? $_get['social_link'][$i]    : false );     $social_network = ( isset( $_get['social_network'][$i] ) ? $_get['social_network'][$i] : false );      // if values present entry, update row     if( $social_id !== false && $social_link !== false && $social_network !== false )     {         $sql  = "update social                   set    social_link = '{$social_link}'                   _id = '{$social_id}' , social_network = '{social_network}'";         $stmt = $conn->prepare($sql);         $stmt->execute();     } }  ?> 

you should alter see fit, recommend utilise parameter binding queries.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -