Hack Forums
how to insert multiple keywords in a single column through registration form? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Webmasters (https://hackforums.net/forumdisplay.php?fid=141)
+---- Forum: Website Construction (https://hackforums.net/forumdisplay.php?fid=50)
+---- Thread: how to insert multiple keywords in a single column through registration form? (/showthread.php?tid=5571302)



how to insert multiple keywords in a single column through registration form? - srcsameer - Mar 10, 2017

i am trying to create a registration form and i have a column where i want to insert multiple values in that single column(catagory) through check Box. is there a possible way to do that? have a look at my php files.

Thank You,

This is my Dboperation.php

PHP Code

<?php 
public function createEmpl($name, $surname, $username, $user_pass, $address, $pin, $mail, $phone, $catagory){
            if(
$this->isUserExist($username,$mail,$phone)){
                    return 
0;
            }else{
                
$password = md5($user_pass);
                
$stmt = $this->con->prepare("INSERT INTO `employee_data` (`name`, `surname`, `username`, `password`, `address`, `pin`, `mail`, `phone`, `catagory`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);");
                
$stmt->bind_Param("sssssssss",$name,$surname,$username,$password,$address,$pin,$mail,$phone,$catagory);

                if(
$stmt->execute()){
                    return 
1;
                }else{
                    return 
2;
                }
            }
        } 

And this is my main registration.php file

PHP Code

<?php 
if(
        isset(
$_POST['reg_name']) and isset($_POST['reg_surname']) and isset($_POST['reg_username']) and isset($_POST['reg_password']) and isset($_POST['reg_address']) and isset($_POST['reg_pin']) and isset($_POST['reg_mail']) and isset($_POST['reg_phone']) and isset($_POST['reg_catagory'])
        ){
        
//operate the data further

        
$db = new DbOperations();

        
$result = $db->createEmpl(    $_POST['reg_name'],
                                    
$_POST['reg_surname'],
                                    
$_POST['reg_username'],
                                    
$_POST['reg_password'],
                                    
$_POST['reg_address'],
                                    
$_POST['reg_pin'],
                                    
$_POST['reg_mail'],
                                    
$_POST['reg_phone'],
                                    
$_POST['reg_catagory']
                                );
        if(
$result == 1){
            
$response['error'] = false;
            
$response['message'] = "User register successfully"; 

Any help will be appreciated.


* - ShadowCloudGH - Mar 10, 2017

Why not have a one to many table saving the categories? While you could save this in one column, I would suggest creating a new table called Employee_Category and saving an EmployeeId against a CategoryId. You could then have multiple records for the same employee in this table?

This will save you a lot of time manipulating strings later on...


* - srcsameer - Mar 10, 2017

(Mar 10, 2017 12:47 AM)ShadowCloudGH Wrote:  Why not have a one to many table saving the categories? While you could save this in one column, I would suggest creating a new table called Employee_Category and saving an EmployeeId against a CategoryId. You could then have multiple records for the same employee in this table?

This will save you a lot of time manipulating strings later on...

Bro... i Didn't get you... i can't change my table or columns i just want is:


while registering one can check checkbox item/s and then selected keywords will be inserted to category column also i want to retrieve that user's id using that keyword. like if i will post checkbox1 then user's who has checkbox1 in their category column their names will be shown. did you get it?


* - ShadowCloudGH - Mar 10, 2017

(Mar 10, 2017 06:03 AM)srcsameer Wrote:  
Bro... i Didn't get you... i can't change my table or columns i just want is:


while registering one can check checkbox item/s and then selected keywords will be inserted to category column also i want to retrieve that user's id using that keyword. like if i will post checkbox1 then user's who has checkbox1 in their category column their names will be shown. did you get it?

Yes, but you clearly didn't get me :)

If you save this in one column, potentially delimited by something like a comma, or heaven forbid a pipe (|) or something even more sinisiter like a combination of chars (#split#) then you end up with the following in the record:

UsrID1>> cat1#split#cat2#split#cat5
UsrID2>> cat1#split#cat3
UsrID3>> cat5
UsrID4>> cat3
UsrID5>> cat1#split#cat3
UsrID6>> cat4#split#cat7

The problem with this is, now if you want all users with cat5 selected in registration, you have no way of getting info without going through all the records in the table.

This is concerned an anti-pattern


* - srcsameer - Mar 10, 2017

(Mar 10, 2017 06:43 AM)ShadowCloudGH Wrote:  Yes, but you clearly didn't get me :)

If you save this in one column, potentially delimited by something like a comma, or heaven forbid a pipe (|) or something even more sinisiter like a combination of chars (#split#) then you end up with the following in the record:

UsrID1>> cat1#split#cat2#split#cat5
UsrID2>> cat1#split#cat3
UsrID3>> cat5
UsrID4>> cat3
UsrID5>> cat1#split#cat3
UsrID6>> cat4#split#cat7

The problem with this is, now if you want all users with cat5 selected in registration, you have no way of getting info without going through all the records in the table.

This is concerned an anti-pattern

Can you just show me by editing my php file Dboperation and registration... i am a learner bro.


(Mar 10, 2017 06:43 AM)ShadowCloudGH Wrote:  Yes, but you clearly didn't get me :)

If you save this in one column, potentially delimited by something like a comma, or heaven forbid a pipe (|) or something even more sinisiter like a combination of chars (#split#) then you end up with the following in the record:

UsrID1>> cat1#split#cat2#split#cat5
UsrID2>> cat1#split#cat3
UsrID3>> cat5
UsrID4>> cat3
UsrID5>> cat1#split#cat3
UsrID6>> cat4#split#cat7

The problem with this is, now if you want all users with cat5 selected in registration, you have no way of getting info without going through all the records in the table.

This is concerned an anti-pattern

Hi! bro please reply... can you show me how to o it? it's really important for me.