maliary Posted May 29, 2007 Share Posted May 29, 2007 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]')"); } } Quote Link to comment https://forums.phpfreaks.com/topic/53388-solved-insert-statement/ Share on other sites More sharing options...
maliary Posted May 30, 2007 Author Share Posted May 30, 2007 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]')"); } } Quote Link to comment https://forums.phpfreaks.com/topic/53388-solved-insert-statement/#findComment-264853 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.