Html form posting, no data passed on

10,335

Solution 1

You should be using the name attribute of input to send the data to a PHP post script. Example:

Form:

<form action="add.php" method="post">
    <input type="text" name="firstname" />
</form>

Script (add.php):

<?php
//print the $_POST['firstname'] variable
echo $_POST['firstname'];
?>

Solution 2

You need to add the name attribute to your input and select elements

<input type="text" name="myinput">

Php will then build your $_POST array with those names.

Share:
10,335
SorenA
Author by

SorenA

Updated on June 14, 2022

Comments

  • SorenA
    SorenA almost 2 years

    I've been sitting with this problem for a while now, can't seem to figure out whats wrong with the code.

    The problem is that no data gets posted from the form to the script.

    <div class="mws-panel-body">
        <form class="mws-form" action="blueprints/add" method="post" id="pForm">
            <div class="mws-form-inline">
                <div class="mws-form-row">
                    <label>Blueprint name</label>
                    <div class="mws-form-item small">
                        <input type="text" class="mws-autocomplete mws-textinput" id="pName" value="" />
                        <div>The name of the blueprint, search completion is enabled.</div>
                    </div>
                </div>
                <div class="mws-form-row">
                    <label>Hangar</label>
                    <div class="mws-form-item micro">
                        <select id="pHangar">
                            <option value="0" selected>Personal</option>
                            <option value="1">Corporation</option>
                        </select>
                        <div>Indicates who the blueprint belongs to.</div>
                    </div>
                </div>
                <div class="mws-form-row">
                    <label>State</label>
                    <div class="mws-form-item micro">
                        <select id="pState">
                            <option value="1" selected>Original</option>
                            <option value="0">Copy</option>
                        </select>
                        <div>The state of the blueprint, be it original or a copy.</div>
                    </div>
                </div>
                <div class="mws-form-row">
                    <label>Productions runs</label>
                    <div class="mws-form-item small">
                        <input type="text" class="mws-textinput" id="pRuns" value="0" />
                        <div>The number of production runs left on copy.</div>
                    </div>
                </div>
                <div class="mws-form-row">
                    <label>Material efficiency</label>
                    <div class="mws-form-item small">
                        <input type="text" class="mws-textinput" id="pME" value="0" />
                        <div>The current material efficiency level of the blueprint.</div>
                    </div>
                </div>
                <div class="mws-form-row">
                    <label>Production efficiency</label>
                    <div class="mws-form-item small">
                        <input type="text" class="mws-textinput" id="pPE" value="0" />
                        <div>The current production efficiency level of the blueprint.</div>
                    </div>
                </div>
            </div>
            <div class="mws-button-row">
                <input type="submit" value="Add blueprint" class="mws-button blue" />
                <input type="reset" value="Reset" class="mws-button gray" />
            </div>
        </form>
    </div>
    

    It seems to be a problem with the form itself, as if the form is set to get, it just enters the script with a question-mark only, blueprints/add?, meaning no data gets passed on at all.

    Any pointers or suggestions will be appreciated.

    My platform is PHP if that helps.

  • asgs
    asgs over 8 years
    Never knew this. Is this how HTML forms work?