Jump to content

Problem in inserting partial data from dropdown to mysql using PHP

Go to solution Solved by Barand,

Recommended Posts


I have an issue to insert data from dropdown to mysql. 

It is inserting the partial data to database

Example: if selection is Account Dept, but inserted only Account.  missing Dept

                if selection is Non Active, inserted only Non. missing Active.

whatever coming after space, it cannot be inserted. It happens only in dropdown control.


In Database, using varchar(30) for column


Pls advice where I did wrong.


Thank you 



Here is my HTML code

                                <select class="form-control" data-placeholder="Choose a Category" name="status">
                                          $sql  = "select * from tbl_parameter where paramhead ='STATUS' order by paramdetails";
                                          $stmt = $pdo->prepare($sql);
                                              while ($row = $stmt->fetch())
                                                $optvalue = $row['paramdetails'];
                                                print '<option value ='.$optvalue.'>' .$row['paramdetails']. '</option>'; 

php code

      $staffid =$_POST['staffid'];
      $staffname =$_POST['staffname'];
      $gender =$_POST['gender'];
      $time = strftime("%X");
      $date = strftime("%B %d,%Y");
      $createdon = date("Y-m-d H:i:s");

      $bool = true;
      $sql="insert into tbl_staff_master(staffid,staffname,gender,department,emailid,hpno,address,city,state,country,status,createdby,createdon,terminal) 
                                values ('$staffid','$staffname','$gender','$department','$emailid','$hpno','$address','$city','$state','$country','$status','$createdby','$createdon','$terminal')";
      $pdo = null;
      print '<script>alert("Saved");</script>';
Link to post
Share on other sites

Where you went wrong was creating variables for nothing, using variables in your query, not using prepared statements, not killing the script after a header redirect, using SELECT * instead of naming the columns you want, creating an unnecessary POST check for "add" when you already have the correct check in place for REQUEST METHOD.............

Link to post
Share on other sites
  • Solution

You are not creating the option values correctly.


Currently you are creating

<option value =Accounts Dept>
What you should create is

<option value="Accounts Dept">
Without the quotes the value is terminated at the space after Accounts.
Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.