Add The curly bracket after
or die (mysql_error());

<?php
//open the db connection
include("connect.php");
//carry on the session array thats holding the data values
session_start();
foreach($_POST as $key => $val)
{
$_SESSION[$key] = $val;
}

if (isset($_POST['Submit'])) {

$contact = $_POST['contact'];
$nameorg = $_POST['nameorg'];
$telephone = $_POST['telephone'];
$besttimecontact = $_POST['besttimecontact'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$town = $_POST['town'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$website = $_POST['website'];
$govoffreg = $_POST['govoffreg'];
$premises = $_POST['premises'];
$commitee = $_POST['commitee'];
$fundingsources = $_POST['fundingsources'];
$bmeorg = $_POST['bmeorg'];
$ethnicityusers = $_POST['ethnicityusers'];
$orgtype = $_POST['orgtype'];
$activities = $_POST['activities'];
$beneficiaries = $_POST['beneficiaries'];
$contactrole = $_POST['contactrole'];
$legalstatus = $_POST['legalstatus'];
$levelorg = $_POST['levelorg'];
$areaop = $_POST['areaop'];
$income = $_POST['income'];
$ft30plus = $_POST['ft30plus'];
$pt16hrs = $_POST['pt16hrs'];
$pt1630hrs = $_POST['pt1630hrs'];
$sessional = $_POST['sessional'];
$trainers = $_POST['trainers'];
$unclassified = $_POST['unclassified'];
$volunteer = $_POST['volunteer'];
$common_whatexpect = $_POST['common_whatexpect'];
$reliable = $_POST['reliable'];
$cheap = $_POST['cheap'];
$personalservice = $_POST['personalservice'];
$slow = $_POST['slow'];
$qualifiedstaff_people = $_POST['qualifiedstaff_people'];
$widechoice = $_POST['widechoice'];
$consistent = $_POST['consistent'];
$approachable = $_POST['approachable'];
$fitforpurpose = $_POST['fitforpurpose'];
$welleducated = $_POST['welleducated'];
$friendly = $_POST['friendly'];
$prompt = $_POST['prompt'];
$attentive = $_POST['attentive'];
$speedy = $_POST['speedy'];
$meetsneeds = $_POST['meetsneeds'];
$takeson = $_POST['takeson'];
$providesxtras = $_POST['providesxtras'];
$handson = $_POST['handson'];
$responsive = $_POST['responsive'];
$ltdselection = $_POST['ltdselection'];
$competent = $_POST['competent'];
$affordable = $_POST['affordable'];
$accessible = $_POST['accessible'];
$knowledgeable = $_POST['knowledgeable'];
$checkssatisfaction = $_POST['checkssatisfaction'];
$getsdetails = $_POST['getsdetails'];
$understands = $_POST['understands'];
$important1 = $_POST['important1'];
$important2 = $_POST['important2'];
$important3 = $_POST['important3'];
$important4 = $_POST['important4'];
$important5 = $_POST['important5'];
$nameofsystems = $_POST['nameofsystems'];
$not_adopting_sys_1 = $_POST['not_adopting_sys_1'];
$not_adopting_sys_2 = $_POST['not_adopting_sys_2'];
$not_adopting_sys_3 = $_POST['not_adopting_sys_3'];
$not_adopting_sys_4 = $_POST['not_adopting_sys_4'];
$not_adopting_sys_5 = $_POST['not_adopting_sys_5'];
$not_adopting_sys_6 = $_POST['not_adopting_sys_6'];
$not_adopting_sys_7 = $_POST['not_adopting_sys_7'];
$not_adopting_sys_8 = $_POST['not_adopting_sys_8'];

$sql = "INSERT INTO nottsvcs (contact, nameorg, telephone, besttimecontact
,address1
,address2
,town
,county
,postcode
,fax
,email
,website
,govoffreg
,premises
,commitee
,fundingsources
,bmeorg
,ethnictyusers
,orgtype
,activities
,beneficiaries
,contactrole
,legalstatus
,levelorg
,areaop
,incomeft30plus
,pt16hrs
,pt1630hrs
,sessional
,trainers
,unclassified
,volunteer
,common_whatexpec
,reliable
,cheap
,personalservice
,slow
,qualifiedstaff_people
,widechoice
,consistent
,approachable
,fitforpurpose
,welleducated
,friendly
,prompt
,attentive
,speedy
,meetsneeds
,takeson
,providesxtras
,handson
,responsive
,ltdselection
,competent
,affordable
,accessible
,knowledgeable
,checkssatisfaction
,getsdetails
,understands
,important1
,important2
,important3
,important4
,important5
,nameofsystems
,not_adopting_sys_1
,not_adopting_sys_2
,not_adopting_sys_3
,not_adopting_sys_4
,not_adopting_sys_5
,not_adopting_sys_6
,not_adopting_sys_7
,not_adopting_sys_8)


VALUES ($_SESSION'['$contact']'
,$_SESSION'['$nameorg']'
,$_SESSION'['$telephone']'
,$_SESSION'['$besttimecontact']'
,$_SESSION'['$address1']'
,$_SESSION'['$address2']'
,$_SESSION'['$town']'
,$_SESSION'['$county']'
,$_SESSION'['$postcode']'
,$_SESSION'['$fax']'
,$_SESSION'['$email']'
,$_SESSION'['$website']'
,$_SESSION'['$govoffreg']'
,$_SESSION'['$premises']'
,$_SESSION'['$commitee']'
,$_SESSION'['$fundingsources']'
,$_SESSION'['$bmeorg']'
,$_SESSION'['$ethnictyusers']'
,$_SESSION'['$orgtype']'
,$_SESSION'['$activities']'
,$_SESSION'['$beneficiaries']'
,$_SESSION'['$contactrole']'
,$_SESSION'['$legalstatus']'
,$_SESSION'['$levelorg']'
,$_SESSION'['$areaop']'
,$_SESSION'['$income']'
,$_SESSION'['$ft30plus']'
,$_SESSION'['$pt16hrs']'
,$_SESSION'['$pt1630hrs']'
,$_SESSION'['$sessional']'
,$_SESSION'['$trainers']'
,$_SESSION'['$unclassified']'
,$_SESSION'['$volunteer']'
,$_SESSION'['$common_whatexpect']'
,$_SESSION'['$reliable']'
,$_SESSION'['$cheap']'
,$_SESSION'['$personalservice']'
,$_SESSION'['$slow']'
,$_SESSION'['$qualifiedstaff_people']'
,$_SESSION'['$widechoice']'
,$_SESSION'['$consistent']'
,$_SESSION'['$approachable']'
,$_SESSION'['$fitforpurpose']'
,$_SESSION'['$welleducated']'
,$_SESSION'['$friendly']'
,$_SESSION'['$prompt']'
,$_SESSION'['$attentive']'
,$_SESSION'['$speedy']'
,$_SESSION'['$meetsneeds']'
,$_SESSION'['$takeson']'
,$_SESSION'['$providesxtras']'
,$_SESSION'['$handson']'
,$_SESSION'['$responsive']'
,$_SESSION'['$ltdselection']'
,$_SESSION'['$competent']'
,$_SESSION'['$affordable']'
,$_SESSION'['$accessible']'
,$_SESSION'['$knowledgeable']'
,$_SESSION'['$checkssatisfaction']'
,$_SESSION'['$getsdetails']'
,$_SESSION'['$understands']'
,$_SESSION'['$important1']'
,$_SESSION'['$important2']'
,$_SESSION'['$important3']'
,$_SESSION'['$important4']'
,$_SESSION'['$important5']'
,$_SESSION'['$nameofsystems']'
,$_SESSION'['$not_adopting_sys_1']'
,$_SESSION'['$not_adopting_sys_2']'
,$_SESSION'['$not_adopting_sys_3']'
,$_SESSION'['$not_adopting_sys_4']'
,$_SESSION'['$not_adopting_sys_5']'
,$_SESSION'['$not_adopting_sys_6']'
,$_SESSION'['$not_adopting_sys_7']'
,$_SESSION'['$not_adopting_sys_8']'

)"
or die (mysql_error());

}
//execute query and store the result

$res = mysql_query($sql,$connection);
if ($res) {
echo "Your survey has been submitted - thankyou<BR /><BR />";

} else {
echo "There was a problem with your post - please click the previous button and try again or contact the system administrator: tez@mindseyemidlands.co.uk<BR /><BR />";
}

?> 

    I changed the position of the curly bracket as suggested but
    error message as says:

    Parse error: parse error, unexpected '}' in /disk1/home3/mindseye/public_html/nottsvcs_short_1_4_formhandler.php on line 744

      You have "or die (mysql_error());"

      After your SQL statement...

      However, your sql statement is only a variable.. you forgot the 'mysql_query("");' part

      change this:
      ,$_SESSION'['$not_adopting_sys_8']'

      )"
      or die (mysql_error());

      to this:
      ,$_SESSION'['$not_adopting_sys_8']'

      )";

      mysql_query($sql) or die (mysql_error());

        Your problem with the undefined indexes is because THEY DO NOT EXIST in $_POST.

        You are taking data from page 1 of your form and saving it in $SESSION, same for page 2 and 3.
        You are doing this because the input from page 1 will be lost when you move to page 2 and so on.
        So on page 4 you have to extract the saved data from $
        SESSION not from $POST because it IS NOT IN $POST, hence the undefined index error.

        By the way, I thought we had already gone through all this elsewhere?

          To extract the data from $session as opposed to $post do I simply replace $post i.e:

          if (isset($_SESSION['Submit']))

          $contact = $SESSION['contact'];
          $nameorg = $
          SESSION['nameorg'];
          $telephone = $SESSION['telephone'];
          $address1 = $
          SESSION['address1'];
          $address2 = $_SESSION['address2'];

          ??????

            Yes Roger we spoke about this:

            http://phpbuilder.com/board/showthread.php?t=10312697

            but the quote_smart approach was not working out. I read up on the link but couldn't figure out how to make use of thr best practice.
            I reposted as I had different error messages but now ive come back to the same problem.

            I have just tried your suggestion in the other thread again with the following which comes out with an undefined variable error:

            Notice: Undefined variable: besttimecontact in /disk1/home3/mindseye/public_html/nottsvcs_short_1_4_formhandler.php on line 257

            here is my code:

            <?php 
            session_start(); 
            foreach($_POST as $key => $val) 
            { 
            $_SESSION[$key] = $val; 
            } 
            
            
            //open the db connection 
            include("connect.php"); 
            
            if (isset($_POST['Submit'])) 
            
            $sql = "INSERT INTO nottsvcs (contact, nameorg, telephone, besttimecontact
            ,address1
            ,address2
            ,town
            ,county
            ,postcode
            ,fax
            ,email
            ,website
            ,govoffreg
            ,premises
            ,commitee
            ,fundingsources
            ,bmeorg
            ,ethnictyusers
            ,orgtype
            ,activities
            ,beneficiaries
            ,contactrole
            ,legalstatus
            ,levelorg
            ,areaop
            ,incomeft30plus
            ,pt16hrs
            ,pt1630hrs
            ,sessional
            ,trainers
            ,unclassified
            ,volunteer
            ,common_whatexpec
            ,reliable
            ,cheap
            ,personalservice
            ,slow
            ,qualifiedstaff_people
            ,widechoice
            ,consistent
            ,approachable
            ,fitforpurpose
            ,welleducated
            ,friendly
            ,prompt
            ,attentive
            ,speedy
            ,meetsneeds
            ,takeson
            ,providesxtras
            ,handson
            ,responsive
            ,ltdselection
            ,competent
            ,affordable
            ,accessible
            ,knowledgeable
            ,checkssatisfaction
            ,getsdetails
            ,understands
            ,important1
            ,important2
            ,important3
            ,important4
            ,important5
            ,nameofsystems
            ,not_adopting_sys_1
            ,not_adopting_sys_2
            ,not_adopting_sys_3
            ,not_adopting_sys_4
            ,not_adopting_sys_5
            ,not_adopting_sys_6
            ,not_adopting_sys_7
            ,not_adopting_sys_8
            ,list_quality_sys_1
            ,list_quality_sys_2
            ,list_quality_sys_3
            ,list_quality_sys_4
            ,list_quality_sys_5
            ,list_quality_sys_6
            ,list_quality_sys_7
            ,list_quality_sys_8
            ,list_quality_sys_9
            ,list_quality_sys_10
            ,list_quality_sys_11
            ,list_quality_sys_12
            ,list_quality_sys_13
            ,list_quality_sys_14
            ,list_quality_sys_15
            ,list_quality_sys_16
            ,list_quality_sys_17
            ,list_quality_sys_18
            ,list_quality_sys_19
            ,list_quality_sys_20
            ,list_quality_sys_21
            ,list_quality_sys_22
            ,list_quality_sys_23
            ,list_quality_sys_24
            ,list_quality_sys_25
            ,list_quality_sys_26
            ,list_quality_sys_27
            ,list_quality_sys_28
            ,list_quality_sys_29
            ,list_quality_sys_30
            ,list_quality_sys_31
            ,list_quality_sys_32
            ,list_quality_sys_33
            ,list_quality_sys_34
            ,list_quality_sys_35
            ,list_quality_sys_36
            ,list_quality_sys_37
            ,list_quality_sys_38
            ,list_quality_sys_39
            ,list_quality_sys_40
            ,list_quality_sys_41
            ,list_quality_sys_42
            ,list_quality_sys_43
            ,list_quality_sys_44
            ,list_quality_sys_45
            ,list_quality_sys_46
            ,list_quality_sys_47
            ,list_quality_sys_48
            ,list_quality_sys_49
            ,list_quality_sys_50
            ,list_quality_sys_51
            ,list_quality_sys_52
            ,list_quality_sys_53
            ,list_quality_sys_54
            ,list_quality_sys_55
            ,list_quality_sys_56
            ,list_quality_sys_57
            ,list_quality_sys_58
            ,how_you_feel_1
            ,how_you_feel_2
            ,how_you_feel_3
            ,how_you_feel_4
            ,how_you_feel_5
            ,how_you_feel_6
            ,how_you_feel_7
            ,how_you_feel_8
            ,how_you_feel_9
            ,clear_view_plan
            ,features_quality_rate_1
            ,features_quality_rate_2
            ,features_quality_rate_3
            ,features_quality_rate_4
            ,features_quality_rate_5
            ,features_quality_rate_6
            ,features_quality_rate_7
            ,features_quality_rate_8
            ,features_quality_rate_9
            ,features_quality_rate_10
            ,features_quality_rate_11
            ,features_quality_rate_12
            ,features_quality_rate_others)
            
            VALUES ($_SESSION'['$contact']'
            ,$_SESSION'['$nameorg']'
            ,$_SESSION'['$telephone']' 
            ,$_SESSION'['$besttimecontact']'
            ,$_SESSION'['$address1']' 
            ,$_SESSION'['$address2']'
            ,$_SESSION'['$town']'
            ,$_SESSION'['$county']'
            ,$_SESSION'['$postcode']'
            ,$_SESSION'['$fax']'
            ,$_SESSION'['$email']'
            ,$_SESSION'['$website']'
            ,$_SESSION'['$govoffreg']'
            ,$_SESSION'['$premises']'
            ,$_SESSION'['$commitee']'
            ,$_SESSION'['$fundingsources']'
            ,$_SESSION'['$bmeorg']'
            ,$_SESSION'['$ethnictyusers']'
            ,$_SESSION'['$orgtype']'
            ,$_SESSION'['$activities']'
            ,$_SESSION'['$beneficiaries']'
            ,$_SESSION'['$contactrole']'
            ,$_SESSION'['$legalstatus']'
            ,$_SESSION'['$levelorg']'
            ,$_SESSION'['$areaop']'
            ,$_SESSION'['$income']'
            ,$_SESSION'['$ft30plus']'
            ,$_SESSION'['$pt16hrs']'
            ,$_SESSION'['$pt1630hrs']'
            ,$_SESSION'['$sessional']'
            ,$_SESSION'['$trainers']'
            ,$_SESSION'['$unclassified']'
            ,$_SESSION'['$volunteer']'
            ,$_SESSION'['$common_whatexpect']'
            ,$_SESSION'['$reliable']'
            ,$_SESSION'['$cheap']'
            ,$_SESSION'['$personalservice']'
            ,$_SESSION'['$slow']'
            ,$_SESSION'['$qualifiedstaff_people']'
            ,$_SESSION'['$widechoice']'
            ,$_SESSION'['$consistent']'
            ,$_SESSION'['$approachable']'
            ,$_SESSION'['$fitforpurpose']'
            ,$_SESSION'['$welleducated']'
            ,$_SESSION'['$friendly']'
            ,$_SESSION'['$prompt']'
            ,$_SESSION'['$attentive']'
            ,$_SESSION'['$speedy']'
            ,$_SESSION'['$meetsneeds']'
            ,$_SESSION'['$takeson']'
            ,$_SESSION'['$providesxtras']'
            ,$_SESSION'['$handson']'
            ,$_SESSION'['$responsive']'
            ,$_SESSION'['$ltdselection']'
            ,$_SESSION'['$competent']'
            ,$_SESSION'['$affordable']'
            ,$_SESSION'['$accessible']'
            ,$_SESSION'['$knowledgeable']'
            ,$_SESSION'['$checkssatisfaction']'
            ,$_SESSION'['$getsdetails']'
            ,$_SESSION'['$understands']'
            ,$_SESSION'['$important1']'
            ,$_SESSION'['$important2']'
            ,$_SESSION'['$important3']'
            ,$_SESSION'['$important4']'
            ,$_SESSION'['$important5']'
            ,$_SESSION'['$nameofsystems']'
            ,$_SESSION'['$not_adopting_sys_1']'
            ,$_SESSION'['$not_adopting_sys_2']'
            ,$_SESSION'['$not_adopting_sys_3']'
            ,$_SESSION'['$not_adopting_sys_4']'
            ,$_SESSION'['$not_adopting_sys_5']'
            ,$_SESSION'['$not_adopting_sys_6']'
            ,$_SESSION'['$not_adopting_sys_7']'
            ,$_SESSION'['$not_adopting_sys_8']'
            ,$_SESSION'['$list_quality_sys_1']'
            ,$_SESSION'['$list_quality_sys_2']'
            ,$_SESSION'['$list_quality_sys_3']'
            ,$_SESSION'['$list_quality_sys_4']'
            ,$_SESSION'['$list_quality_sys_5']'
            ,$_SESSION'['$list_quality_sys_6']'
            ,$_SESSION'['$list_quality_sys_7']'
            ,$_SESSION'['$list_quality_sys_8']'
            ,$_SESSION'['$list_quality_sys_9']'
            ,$_SESSION'['$list_quality_sys_10']'
            ,$_SESSION'['$list_quality_sys_11']'
            ,$_SESSION'['$list_quality_sys_12']'
            ,$_SESSION'['$list_quality_sys_13']'
            ,$_SESSION'['$list_quality_sys_14']'
            ,$_SESSION'['$list_quality_sys_15']'
            ,$_SESSION'['$list_quality_sys_16']'
            ,$_SESSION'['$list_quality_sys_17']'
            ,$_SESSION'['$list_quality_sys_18']'
            ,$_SESSION'['$list_quality_sys_19']'
            ,$_SESSION'['$list_quality_sys_20']'
            ,$_SESSION'['$list_quality_sys_21']'
            ,$_SESSION'['$list_quality_sys_22']'
            ,$_SESSION'['$list_quality_sys_23']'
            ,$_SESSION'['$list_quality_sys_24']'
            ,$_SESSION'['$list_quality_sys_25']'
            ,$_SESSION'['$list_quality_sys_26']'
            ,$_SESSION'['$list_quality_sys_27']'
            ,$_SESSION'['$list_quality_sys_28']'
            ,$_SESSION'['$list_quality_sys_29']'
            ,$_SESSION'['$list_quality_sys_30']'
            ,$_SESSION'['$list_quality_sys_31']'
            ,$_SESSION'['$list_quality_sys_32']'
            ,$_SESSION'['$list_quality_sys_33']'
            ,$_SESSION'['$list_quality_sys_34']'
            ,$_SESSION'['$list_quality_sys_35']'
            ,$_SESSION'['$list_quality_sys_36']'
            ,$_SESSION'['$list_quality_sys_37']'
            ,$_SESSION'['$list_quality_sys_38']'
            ,$_SESSION'['$list_quality_sys_39']'
            ,$_SESSION'['$list_quality_sys_40']'
            ,$_SESSION'['$list_quality_sys_41']'
            ,$_SESSION'['$list_quality_sys_42']'
            ,$_SESSION'['$list_quality_sys_43']'
            ,$_SESSION'['$list_quality_sys_44']'
            ,$_SESSION'['$list_quality_sys_45']'
            ,$_SESSION'['$list_quality_sys_46']'
            ,$_SESSION'['$list_quality_sys_47']'
            ,$_SESSION'['$list_quality_sys_48']'
            ,$_SESSION'['$list_quality_sys_49']'
            ,$_SESSION'['$list_quality_sys_50']'
            ,$_SESSION'['$list_quality_sys_51']'
            ,$_SESSION'['$list_quality_sys_52']'
            ,$_SESSION'['$list_quality_sys_53']'
            ,$_SESSION'['$list_quality_sys_54']'
            ,$_SESSION'['$list_quality_sys_55']'
            ,$_SESSION'['$list_quality_sys_56']'
            ,$_SESSION'['$list_quality_sys_57']'
            ,$_SESSION'['$list_quality_sys_58']'
            ,$_SESSION'['$how_you_feel_1']'
            ,$_SESSION'['$how_you_feel_2']'
            ,$_SESSION'['$how_you_feel_3']'
            ,$_SESSION'['$how_you_feel_4']'
            ,$_SESSION'['$how_you_feel_5']'
            ,$_SESSION'['$how_you_feel_6']'
            ,$_SESSION'['$how_you_feel_7']'
            ,$_SESSION'['$how_you_feel_8']'
            ,$_SESSION'['$how_you_feel_9']'
            ,$_SESSION'['$clear_view_plan']'
            ,$_SESSION'['$features_quality_rate_1']'
            ,$_SESSION'['$features_quality_rate_2']'
            ,$_SESSION'['$features_quality_rate_3']'
            ,$_SESSION'['$features_quality_rate_4']'
            ,$_SESSION'['$features_quality_rate_5']'
            ,$_SESSION'['$features_quality_rate_6']'
            ,$_SESSION'['$features_quality_rate_7']'
            ,$_SESSION'['$features_quality_rate_8']'
            ,$_SESSION'['$features_quality_rate_9']'
            ,$_SESSION'['$features_quality_rate_10']'
            ,$_SESSION'['$features_quality_rate_11']'
            ,$_SESSION'['$features_quality_rate_12']'
            ,$_SESSION'['$features_quality_rate_others']'
            
            )";
            
            mysql_query($sql) or die (mysql_error());
            
            
            //execute query and store the result
            
            $res = mysql_query($sql,$connection);
            if ($res) {
            echo "Your survey has been submitted - thankyou<BR /><BR />";
            
            } else {
            echo "There was a problem with your post - please click the previous button and try again or contact the system administrator: tez@mindseyemidlands.co.uk<BR /><BR />";
            }
            
            ?>
            

            I cannot win either way at the moment as this creates an undefined variable error and if I do it the other way with POST then I have undefined indexes

              What are you trying to write in here?

              VALUES ($_SESSION'['$contact']'
              ,$_SESSION'['$nameorg']'
              ,$_SESSION'['$telephone']' 
              //etc
              

              If I know anything about PHP I can see that this is way wrong... It should be:

              VALUES ('$_SESSION[contact]'
              ,'$_SESSION[nameorg]'
              ,'$_SESSION[telephone]' 
              //etc
              

              ...but only if contact, nameorg, telephone etc. are values you gather from the form (are field names in the form) i.e. are present in the $_POST array where they are represented as $POST['contact'], $POST['nameorg'] etc. And after that litle piece of code that transfroms these into session variables they become $SESSION['contact'], $SESSION['nameorg'] etc.

              Quotes go on the outside of the value that you try to implement into SQL query and thus they all become '$_SESSION[contact]' and such...

              Hope this is helpful in any way...

                Tezread wrote:

                To extract the data from $session as opposed to $post do I simply replace $post i.e:

                if (isset($_SESSION['Submit']))

                $contact = $SESSION['contact'];
                $nameorg = $
                SESSION['nameorg'];
                $telephone = $SESSION['telephone'];
                $address1 = $
                SESSION['address1'];
                $address2 = $_SESSION['address2'];

                ??????

                Yes, that is exactly right. I copy/pasted from your code and forgot to take out the $ signs - see my signature.

                Now, for some reason my last post in the other thread has not shown up??? In it I showed you how I personally handle stuff like this; so here goes again.

                Since you are just after building a query string from all these vars, you can automate the process a lot instead of typing out all those var names.

                // at the top of each form processing page you need this little bit of code
                
                require_once('common_functions.php');     // includes the quote_smart function
                
                if (isset($_POST['submit'])) {
                
                foreach ($_POST as $key=>$val) {
                
                // build the column name list
                $_SESSION['cols'] .= $key . ',';
                // and the values list
                $_SESSION['vals'] .= quote_smart($val) . ',';  
                // and you MUST quote_smart to get the correct quotes around the values or the final query will fail } } // then in the form processing script you just need to clean up these 2 string and insert them into the query string $strcols = rtrim($_SESSION['cols'], ','); // remove final comma $strvals = rtrim($_SESSION['vals'], ','); $sql = "INSERT INTO nottsvcs (" . $strcols . ") VALUES (" . $strvals . ")"; echo $sql; // to see the query string you've built

                This method saves a lot of typing, and will not need alteration if you add or remove fields in the forms. I have not included any form validation for required fields, required data types etc to keep things simple, but data validation should always be done somewhere.

                  Looks impressive- what is happening inside common_functions.php.?

                  Also im not sure how to how to go about cleaning up the strings you refer to.

                  // then in the form processing script you just need to clean up these 2 string and insert them into the query string 
                  
                  $strcols = rtrim($_SESSION['cols'], ',');  // remove final comma 
                  $strvals = rtrim($_SESSION['vals'], ','); 
                  

                  As it stands I get the Undefined error message again- im confused as to how to rectify as your solution avoids using that long list of vars which is a good thing

                    Roger- thankyou for all your help by the way.
                    This is a dynamic approach as you can add fields to the forms easily plus the added security is a bonus with the quote_smart function.
                    I hope I have interpreted your code correctly as I have an error message now:

                    Notice: Undefined variable: _SESSION in /disk1/home3/mindseye/public_html/nottsvcs_short_1_4_formhandler.php on line 7

                    Notice: Undefined variable: _SESSION in /disk1/home3/mindseye/public_html/nottsvcs_short_1_4_formhandler.php on line 8
                    INSERT INTO nottsvcs () VALUES ()

                    This is the code I have a the top of each of the forms:

                    <?php
                    // at the top of each form processing page you need this little bit of code 
                    
                    require_once('common_functions.php'); // includes the quote_smart function 
                    
                    if (isset($_POST['submit'])) { 
                    
                    foreach ($_POST as $key=>$val) { 
                    
                    // build the column name list 
                    $_SESSION['cols'] .= $key . ','; 
                    // and the values list 
                    $_SESSION['vals'] .= quote_smart($val) . ','; 
                    
                    } 
                    } 
                    
                    
                    ?>
                    

                    This is the final formhandler:

                    
                    <?php
                    include("connect.php");
                    
                    
                    $strcols = rtrim($_SESSION['cols'], ',');  
                    $strvals = rtrim($_SESSION['vals'], ','); $sql = "INSERT INTO nottsvcs (" . $strcols . ") VALUES (" . $strvals . ")"; echo $sql;
                    ?>

                      Those error messages look like you have a typo or two

                      SESSION not $SESSION

                      Are you sure you are pasting the code exactly as you are using it?

                      One thing occurs to me though: when concatenating each value to the existing string $_SESSION['vals'], php may loose the quotes around string entries cos it's concating a string to a string. If it does then just amend the code to

                      $_SESSION['vals'] .= "'" . quote_smart($val) . "',";
                      

                      That should embed the single quotes around the strings that sql requires.

                      Correction, you are missing the session_start() at the top of formhandler.

                        I am agonizingly close to success here. I get an error message stating:

                        Parse error: parse error, unexpected '[' in /disk1/home3/mindseye/public_html/nottsvcs_short_1_4_formhandler.php on line 19

                        I took replaced $SESSION and made this into SESSION though this has caused the error message above. Since reading your last post ive spent almost 2 hours looking up the error message above but it is not mentioned on this forum alas.

                        Here is my final formhander:

                        
                        <?php 
                        session_start();
                        
                        require_once('common_functions.php'); // includes the quote_smart function 
                        
                        if (isset($_POST['submit'])) { 
                        
                        foreach ($_POST as $key=>$val) { 
                        
                        // build the column name list 
                        $_SESSION['cols'] .= $key . ','; 
                        // and the values list 
                        $_SESSION['vals'] .= quote_smart($val) . ','; 
                        
                        } 
                        } 
                        include("connect.php"); 
                        // this is where I replaced $_SESSION for _SESSION
                        
                        $strcols = rtrim(_SESSION['cols'], ',');   
                        $strvals = rtrim(_SESSION['vals'], ','); $sql = "INSERT INTO nottsvcs (" . $strcols . ") VALUES (" . $strvals . ")"; echo $sql; ?>

                        Here is the common_functions.php code

                        <?php
                        function quote_smart($val) { 
                        session_start(); 
                        foreach($_POST as $key => $val) 
                        { 
                        $_SESSION[$key] = quote_smart($val);      
                        } } ?>

                          Your error message is because you tok the $ off the front of $SESSION. $SESSION is an array so the [] are expected. _SESSIOn on the other hand is just declaring a new var and [] are not permitted in var names. Put the $ signs back

                          $strcols = rtrim($_SESSION['cols'], ',');   
                          $strvals = rtrim($_SESSION['vals'], ','); //now echo them just for debugging echo $strcols; echo $strvals; //remove the echos once it is working

                          Now, your common functions is all to pot. I always have a file called common.php in which I have the functions that I will use on almost every web site and script. I have copied and pasted the quote_smart function directly from the manual without alteration. Just use it as is. Copy the whole thing into your editor and save the file - this is a complete file from <? to ?>.

                          
                          <?php   
                          
                          // Quote variable to make safe
                          function quote_smart($value)
                          {
                             // Stripslashes
                             if (get_magic_quotes_gpc()) {
                                 $value = stripslashes($value);
                             }
                             // Quote if not integer
                             if (!is_numeric($value)) {
                                 $value = "'" . mysql_real_escape_string($value) . "'";
                             }
                             return $value;
                          }
                          ?>
                          

                            Dear Lord! now the error message is back to the Undefined Index- how can this be when $strcols and $strvals has been declared

                            Notice: Undefined index: cols in /disk1/home3/mindseye/public_html/nottsvcs_short_1_4_formhandler.php on line 19

                            Notice: Undefined index: vals in /disk1/home3/mindseye/public_html/nottsvcs_short_1_4_formhandler.php on line 20
                            INSERT INTO nottsvcs () VALUES ()

                            Here is the code up to date- the common _functions.php is verbatum but here is the formhandler:

                            
                            <?php 
                            session_start();
                            
                            require_once('common_functions.php'); // includes the quote_smart function 
                            
                            if (isset($_POST['submit'])) { 
                            
                            foreach ($_POST as $key=>$val) { 
                            
                            // build the column name list 
                            $_SESSION['cols'] .= $key . ','; 
                            // and the values list 
                            $_SESSION['vals'] .= quote_smart($val) . ','; 
                            
                            } 
                            } 
                            include("connect.php"); 
                            
                            $strcols = rtrim($_SESSION['cols'], ',');    
                            $strvals = rtrim($_SESSION['vals'], ','); //now echo them just for debugging echo $strcols; echo $strvals; //remove the echos once it is working $sql = "INSERT INTO nottsvcs (" . $strcols . ") VALUES (" . $strvals . ")"; echo $sql; ?>

                              What is the name of your submit button? $SESSION['cols'] does not exist: must be because isset($POST['submit]) is FALSE = there is no var in the $_POST array called 'submit'.

                              debugging 1010, when you get an error, insert echo messages to track the processing of control structures like IF/ELSE etc. Work your way through the script step by step echoing each var until you find which one is not as you expect.

                              I personally use the foreach($POST or $GET ... to echo out all names and values of post/get arrays when I'm first testing my scripts to see that I'm getting the data I should to begin with. I especially have to do that because, as my sig says, I'm always full of typos.

                                Sorry im lost now- the submit buttons in each of my multipage form are named 'submit'.

                                This is an example of part 1 of my form:

                                
                                <?php 
                                // at the top of each form processing page I have put this code
                                
                                require_once('common_functions.php'); // includes the quote_smart function 
                                
                                if (isset($_POST['submit'])) { 
                                
                                foreach ($_POST as $key=>$val) { 
                                
                                // build the column name list 
                                $_SESSION['cols'] .= $key . ','; 
                                // and the values list 
                                $_SESSION['vals'] .= quote_smart($val) . ','; 
                                // and you MUST quote_smart to get the correct quotes around the values or the final query will fail 
                                } 
                                } 
                                
                                
                                ?> 
                                .....blah blah blah
                                
                                
                                //action here takes you to the 2nd part of the form  
                                
                                <form name="form1" method="post" action="nottsvcs_placeyourorganisation_short.php">
                                
                                
                                .......blah blah blah form here
                                
                                    <td>Click Submit to save your details <br>          <br>
                                    <input type="submit" name="Submit" value="Submit"></td>
                                
                                

                                  In php var names are case-sensitive, so Submit is not the same as submit.

                                  That is why the session vars are not being created, the foreach loops are not being processed. Make it a habit to put echos in so that you can track conditional processing in if statements and while loops etc. You can take them out once they prove your logic.

                                    Tnx for your patience Roger- I wish I was experienced enough to mentor yourself:

                                    Line 12 in common_functions results in:

                                    Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user: 'root@localhost' (Using password: NO) in /disk1/home3/mindseye/public_html/common_functions.php on line 12

                                      EH???? Best ask someone else what that means. Looks like you don't have access to the inbuilt function musql_real_escape_string? Does not make sense to me.

                                      Post the error message as a new thread in the coding forum. See if anyone knows it, weedpackets sure to have a good idea what it is. May be a bug in your version, but could be anything.

                                        Write a Reply...