php - insert array element into database -


i have function : it's work correctly,

function ms_get_did_detail($id) {     global $link;     $q2="select dest,priority destpr id='$id'";      if($res2=mssql_query($q2)) {         while($row2[]=mssql_fetch_array($res2,mssql_assoc)) {             return $row2;         }          return 0;     }      return 0; } 

i want insert every element (every dest & priority) mysql

if($info=ms_get_did_detail($value)) {     print_r($info);     $destination = $info['dest'];     $priority = $info['priority'];     my_did_destination ($priority , $dest , $active , $did_voip , $cc_id);                  }      

it returns array :

[0]=> array (     [dest] => 100     [priority] => 1 ) [1]=> array (     [dest] => 200      [priority] => 3  )  [2] => ( ) 

also , have function insert value in database :

function my_did_destination($priority="",$destination="") {     global $link_voip;     $sql="insert cc_did_destination (destination,priority)            values ('$destination','$priority')";      $retval = mysql_query( $sql , $link_voip);      if(! $retval ) {         die('could not enter data: ' . mysql_error());     } } 

but it's insert empty value within

you inserting rows id of 0, so, if row id=0 exists, fail , not inserted.

maybe easiest solution make yout id column autoincrement sql statement like:

    alter table cc_did_destination    modify column id int auto_increment; 

and change insert statement for:

  $sql="insert cc_did_destination (destination,priority)               values ('$destination','$priority')"; 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -