[left]Hi, i am trying to insert my form to database but my radio buttons are creating the problems. Basically, i have 2 radio button sections (specialization and skillsets) and skillsets’ value will taken according to the specialization. When inserting to the database, “array” word will be shown in specialization column and nothing is shown in skillsets column. I have no idea where i am getting wrong at but i suspect it has something to do with declaring my skillsets inside my specialization brackets. Here is my code-
PHP Code:
[code][php]
<?php // form action goes here $addProfileForm = htmlentities($_SERVER['PHP_SELF']); // start of database dependent code try{ //check all $_POST //echo ''; // //print_r($_POST); // //echo ''; // assuming that both the get method/display code (form) and form processing need a database connection (needed for all the queries) require('Connections/database.php'); // check for post method form processing if ($_SERVER['REQUEST_METHOD'] == 'POST') { // array to hold errors $errors = array(); // copy and trim all post data $data= array();//array_map('trim',$_POST); array_walk_recursive($data,'trim'); // addprofileform form processing code - //check if there is an existing record in DB $query = "SELECT COUNT(*) FROM userProfile WHERE user_id in ( select id from users where id = ".($_SESSION['user_id']).")"; //var_dump($query); $stmt = $database->query($query); $number_of_rows = $stmt->fetchColumn(); if ($number_of_rows > 0) { $errors[] = "There is an existing record. You cannot insert another profile! Either update the old one, or delete to insert again."; } // if no errors at this point, continue with validation if(empty($errors)){ // all your form field validation code would go here, using elements in the $data array (a trimmed copy of the $_POST data) //validate here after declaring them $data['specialization'] = $_POST['specialization']; $data['ISGrp1'] = $_POST['ISgrp1']; $data['ISGrp2'] = $_POST['ISgrp2']; $data['ISGrp3'] = $_POST['ISgrp3']; $data['ISGrp4'] = $_POST['ISgrp4']; $data['ISGrp5'] = $_POST['ISgrp5']; $data['IMGrp1'] = $_POST['IMgrp1']; $data['IMGrp2'] = $_POST['IMgrp2']; $data['IMGrp3'] = $_POST['IMgrp3']; $data['IMGrp4'] = $_POST['IMgrp4']; $data['IMGrp5'] = $_POST['IMgrp5']; $data['CNETGrp1'] = $_POST['CNETgrp1']; $data['CNETGrp2'] = $_POST['CNETgrp2']; $data['CNETGrp3'] = $_POST['CNETgrp3']; $data['CNETGrp4'] = $_POST['CNETgrp4']; $data['CNETGrp5'] = $_POST['CNETgrp5']; $data['ITSMGrp1'] = $_POST['ITSMgrp1']; $data['ITSMGrp2'] = $_POST['ITSMgrp2']; $data['ITSMGrp3'] = $_POST['ITSMgrp3']; $data['ITSMGrp4'] = $_POST['ITSMgrp4']; $data['ITSMGrp5'] = $_POST['ITSMgrp5']; $skillset = ""; if (isset($data['specialization']) && $data['specialization'] == 'Specialization_1') { $data['specialization'] = "IS"; $skillset = ($data['ISgrp1'].",".$data['ISgrp2'].",".$data['ISgrp3'].",".$data['ISgrp4'].",".$data['ISgrp5']); } if (isset($data['specialization']) && $data['specialization'] == 'Specialization_2') { $data['specialization'] = "IM"; $skillset = ($data['IMgrp1'].",".$data['IMgrp2'].",".$data['IMgrp3'].",".$data['IMgrp4'].",".$data['IMgrp5']); } if (isset($data['specialization']) && $data['specialization'] == 'Specialization_3') { $data['specialization']= "CNET"; $skillset = ($data['CNETgrp1'].",".$data['CNETgrp2'].",".$data['CNETgrp3'].",".$data['CNETgrp4'].",".$data['CNETgrp5']); } if (isset($data['specialization']) && $data['specialization'] == 'Specialization_4') { $data['specialization'] = "ITSM"; $skillset = ($data['ITSMgrp1'].",".$data['ITSMgrp2'].",".$data['ITSMgrp3'].",".$data['ITSMgrp4'].",".$data['ITSMgrp5']); } } //Because, it's in array? either serialize or this o.o json_encode($data); // done with validation, if no errors, use the data - if(empty($errors)){ // your code to insert the data and move the uploaded file would go here... $stmt = $database->prepare("INSERT INTO userProfile (username, Name, introduction, Specialization,skillset, Email, ContactNo, user_Id) VALUES (:username, :Name,:introduction,:Specialization,:skillset,:Email,:ContactNo, :user_Id)"); //$stmt->bindValue(':picName',$_FILES['image']['name']); //$stmt->bindValue(':picPath', $imgDir); $stmt->bindValue(':username',$data['username']); $stmt->bindValue(':Name', $data['name']); $stmt->bindValue(':introduction',$data['introduction']); $stmt->bindValue(':Specialization',$data['specialization']); $stmt->bindValue(':skillset', $skillset); $stmt->bindValue(':Email',$data['email']); $stmt->bindValue(':ContactNo',$data['contactNo']); $stmt->bindValue(':user_Id',$_SESSION['user_id']); $stmt->execute(); } // if no errors at this point, redirect to the exact same url of this page to prevent the browser from resubmitting the data by causing a get request for the page if(empty($errors)){ $host = $_SERVER['HTTP_HOST']; $uri = $_SERVER['REQUEST_URI']; header("Location:addProfile.php?success=1"); exit; } // if there were errors in any of the above form processing code, continue on this page, displaying any errors, redisplay form, (re)populate the form fields with data... foreach($errors as $error) { printf("
[/php][/code]