Jump to content

[SOLVED] Insert Statement


maliary

Recommended Posts

Hi,

 

I am trying to insert a value -- $perio -- in the database that comes from adding two strings that have been posted.

 

If I try to print out $perio in the loop the correct out put is produced which is &carand=2&laptan=7&=.

 

If I print it outside the loop I only get &=.

 


            if ($_SERVER['REQUEST_METHOD'] == "POST") 
      {
     $totalRec = $_POST['total_records']; 
     
       $totalRec = 2;
     
    // echo   $totalRec;
          if (isset($_POST['total_records']) ){  
   
     for ( $counter=0; $counter<=$totalRec; $counter ++) {  
     $perio='&'.$_POST['name'.$counter].'='.$_POST['test_value'.$counter];
      echo  $perio;  
   
     }	  
            
         echo  $perio;                
   $dbtable = 'care_test_findings_chemlab';
   $recs = $db -> Execute("INSERT INTO $dbtable (`encounter_nr`,`job_id`,`test_date`,`test_time`,`group_id`,`type`,`name`,`test_value`,`ranges`,`perio`,`msr_unit`,`serio`,`validator`,`validate_dt`,`status`,`history`,`create_id`,`create_time`) VALUES ('$_POST[encounter_nr]','$_POST[job_id]','$_POST[test_date]','$_POST[test_time]','$_POST[parameterselect]','$_POST[type]','$_POST[name]','$_POST[test_value]','$_POST[range]','".$perio."','$_POST[msr_unit]','$rio','$_POST[validator]','$_POST[validate_dt]','$_POST[status]','$_POST[history]','$_POST[create_id]','$_POST[create_time]')");
                                    
          } 
      }

Link to comment
https://forums.phpfreaks.com/topic/53388-solved-insert-statement/
Share on other sites

Got it!

 

 

if ($_SERVER['REQUEST_METHOD'] == "POST") 
      {
     $totalRec = $_POST['total_records']; 

initialise the variable:
     $perio = NULL;

       $totalRec = 2;
     
    // echo   $totalRec;
          if (isset($_POST['total_records']) ){  
   
     for ( $counter=0; $counter<=$totalRec; $counter ++) { 
[i]Append all other variables in the loop here. [/i]
     $perio=$perio.'&'.$_POST['name'.$counter].'='.$_POST['test_value'.$counter];
      echo  $perio;  
   
     }	  
            
         echo  $perio;                
   $dbtable = 'care_test_findings_chemlab';
   $recs = $db -> Execute("INSERT INTO $dbtable (`encounter_nr`,`job_id`,`test_date`,`test_time`,`group_id`,`type`,`name`,`test_value`,`ranges`,`perio`,`msr_unit`,`serio`,`validator`,`validate_dt`,`status`,`history`,`create_id`,`create_time`) VALUES ('$_POST[encounter_nr]','$_POST[job_id]','$_POST[test_date]','$_POST[test_time]','$_POST[parameterselect]','$_POST[type]','$_POST[name]','$_POST[test_value]','$_POST[range]','".$perio."','$_POST[msr_unit]','$rio','$_POST[validator]','$_POST[validate_dt]','$_POST[status]','$_POST[history]','$_POST[create_id]','$_POST[create_time]')");
                                    
          } 
      }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.