1. #1
    Sencha User
    Join Date
    Jun 2014
    Posts
    7
    Vote Rating
    0
    Answers
    1
    people is on a distinguished road

      0  

    Default Answered: How do I send the text or value from 'selectfield' to a MySQL database using PHP?

    Answered: How do I send the text or value from 'selectfield' to a MySQL database using PHP?


    For example, in my survey.js, say I select Department 1 from the dropdown, I then want to send 'Department 1', or its value '1' to my database.
    Note: Right now my submit.php returns an error that $department is undefined. I believe that either there is another way I have define $department in my PHP or declare something else in my 'survey.js'.

    survey.js:

    Code:
    Ext.define('survey.view.Survey', {
        extend: 'Ext.form.Panel',
        xtype : 'survey',
    
    
        requires: ['Ext.form.*',
            'Ext.field.*',
            'Ext.Button',
            'Ext.Toolbar',
            'Ext.data.Store',
            'Ext.form.FieldSet'
        ],
    
    
        config: {
            cls: 'survey',
            scrollable: true,
            styleHtmlContent: true,
            fullscreen:true,
            url: 'submit.php',
    
    
            layout: {
                type: 'vbox',
                pack: 'center',
                align: 'center'
            },
    
    
            items:
                [
                   
                    {                    
                        defaults: {
                            required: false
                        },
    
    
                        items: [
                            {
                                html: 'Department',
                                padding: '6px'
                            },
                            {
                                xtype: 'fieldset',
                                items: [
                                    {
                                        xtype: 'selectfield',
                                        name: 'department',
                                        id: 'department',
    
    
                                        autoSelect: false,
                                        placeHolder: 'Select...',
                                        options: [
                                            {text: 'Construction and Materials' , value: '1'},
                                            {text: 'General Services', value: '2'},
                                            {text: 'Information Systems', value: '3'},
                                            {text: 'Maintenance', value: '4'},
                                            {text: 'Planning', value: '5'},
                                            {text: 'Project Development', value: '6'},
                                            {text: 'Right Of Way', value: '7'},
                                            {text: 'Traffic', value: '8'}
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
    
    
                    {
                        xtype: 'toolbar',
                        docked: 'bottom',
                        height: 35,
    
    
                        layout:{
                            pack:'center',
                            align:'center'
                        },
    
    
                        scrollable: {
                            direction: 'horizontal',
                            //direction: 'vertical',
                            directionLock: true
                        },
                        items: [                       
                            {
                               text: 'Submit',
                                ui: 'confirm',
                                width: 100,
    
    
                                handler: function() {
                                    this.up('survey').submit();                             
                                    Ext.Viewport.setActiveItem(Ext.widget('thanks'))
                                }
                            }
                        ]
                    }
                ]
        }
    });


    submit.php:

    PHP Code:
    <?php 

                   $db 
    = new PDO("mysql:dbname=survey; host=localhost""root""pass"); 

                   
    $department $_POST['department']; 

                   
    $query "insert into questions                
                   values('"
    .$department."', )"

                   
    $result $db -> query($query); 

               
    ?>

  2. Well I figured it out somehow. Turns out my original solution was correct I just had some commenting issues and code misplacement on my working solution. Thanks for your responses tho fmoseley.

    Here is my reformatted PHP code that pulls from the selectfield.

    PHP Code:
    <?php
    session_start
    ();
    $name $_SESSION['name'];#passed variable
    $db = new PDO("mysql:dbname=survey; host=localhost""root""pass");
    $department $_POST['department'];
    $query "insert into questions
    VALUES('"
    .$name."','".$department."' )";
    $result $db -> query($query);
    ?>

  3. #2
    Sencha - Support Team
    Join Date
    Oct 2011
    Posts
    3,978
    Vote Rating
    132
    Answers
    335
    fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all

      0  

    Default


    Please edit your original post and use [code] tags. You may get more help if your code is more readable. Have you verified that the form submit was successful and the parameter was passed in the network panel?
    Get more personalized support via a support subscription.

    Want to learn Sencha Touch 2? Check out
    Sencha training
    Sencha Touch in Action

    Need more help with your app? Hire Sencha Services services@sencha.com

    When posting code, please use BBCode's CODE tags.

    Need to include a test case use:
    The official Sencha Fiddle

  4. #3
    Sencha User
    Join Date
    Jun 2014
    Posts
    7
    Vote Rating
    0
    Answers
    1
    people is on a distinguished road

      0  

    Default


    The submission is successful, in where it calls 'submit.php' but the parameter of 'department' is not being successfully retrieved because I don't know how to find it. I want to send either the value or text to 'submit.php' and assign it to my '$department' variable using PHP. I believe I have to define something different or new in my 'survey.js' code in order to specify what I am trying to receive, or in my 'php' file so that it knows where to pull the parameter from.

    Note: I know for a fact that for my 'xtype', if I were to use a 'textfield' I could pull the textfields value using the same php code because it knows where to find the textfield value because I declared its 'id'. But I need a selectfield, and I need help figuring out how to pull the values to php so that I can put it in MySQL.

  5. #4
    Sencha - Support Team
    Join Date
    Oct 2011
    Posts
    3,978
    Vote Rating
    132
    Answers
    335
    fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all

      0  

    Default


    Place the following statement. After you assign $department. What is returned in the requests response tab?
    Code:
    echo($department);
    Get more personalized support via a support subscription.

    Want to learn Sencha Touch 2? Check out
    Sencha training
    Sencha Touch in Action

    Need more help with your app? Hire Sencha Services services@sencha.com

    When posting code, please use BBCode's CODE tags.

    Need to include a test case use:
    The official Sencha Fiddle

  6. #5
    Sencha User
    Join Date
    Jun 2014
    Posts
    7
    Vote Rating
    0
    Answers
    1
    people is on a distinguished road

      0  

    Default


    <br />
    <b>Notice</b>: Undefined index: department in <b>C:\xampp\htdocs\survey\submit.php</b> on line <b>7</b><br />
    5

  7. #6
    Sencha User
    Join Date
    Jun 2014
    Posts
    7
    Vote Rating
    0
    Answers
    1
    people is on a distinguished road

      0  

    Default


    Well I figured it out somehow. Turns out my original solution was correct I just had some commenting issues and code misplacement on my working solution. Thanks for your responses tho fmoseley.

    Here is my reformatted PHP code that pulls from the selectfield.

    PHP Code:
    <?php
    session_start
    ();
    $name $_SESSION['name'];#passed variable
    $db = new PDO("mysql:dbname=survey; host=localhost""root""pass");
    $department $_POST['department'];
    $query "insert into questions
    VALUES('"
    .$name."','".$department."' )";
    $result $db -> query($query);
    ?>

  8. #7
    Sencha - Support Team
    Join Date
    Oct 2011
    Posts
    3,978
    Vote Rating
    132
    Answers
    335
    fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all

      0  

    Default


    Thanks for the update and sharing your solution
    Get more personalized support via a support subscription.

    Want to learn Sencha Touch 2? Check out
    Sencha training
    Sencha Touch in Action

    Need more help with your app? Hire Sencha Services services@sencha.com

    When posting code, please use BBCode's CODE tags.

    Need to include a test case use:
    The official Sencha Fiddle

Thread Participants: 1

Tags for this Thread