Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    problems with $_POST

    Hi guys,

    Everytime I run the query to insert into database I get this error :

    Notice: Undefined index: online in E:\Program Files\EasyPHP 2.0b1\www\jetva\insert2.php on line 12
    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, Last Name, E-mail, Country, Password, Hub, Online, ID, Transfer, Extra) V' at line 1

    Application.php
    PHP Code:
    <style type="text/css">
    <!--
    .
    style1 {
        
    font-familyVerdanaArialHelveticasans-serif;
        
    font-size9px;
    }
    -->
    </
    style>
    <
    body>

    <
    form action="insert2.php" method="post" class="style1">
      <
    p align="center">Firstname
        <
    input type="text" name="firstname" />
    </
    p>
      <
    p align="center">Last Name 
        <
    input type="text" name="lastname" />
      </
    p>
      <
    p align="center">E-Mail Address :
        <
    input type="text" name="email" />
      </
    p>
      <
    p align="center">Country :  
        <
    select name="country">
          <
    option value=""></option>
          <
    option value="AF">Afghanistan</option>
          <
    option value="AL">Albania</option>
          <
    option value="DZ">Algeria</option>
          <
    option value="AO">Angola</option>
          <
    option value="AI">Anguilla</option>
          <
    option value="AG">Antigua &ampBarbuda</option>
          <
    option value="AR">Argentina</option>
          <
    option value="AM">Armenia</option>
          <
    option value="AW">Aruba</option>
          <
    option value="AU">Australia</option>
          <
    option value="AT">Austria</option>
          <
    option value="AZ">Azerbaijan</option>
          <
    option value="AP">Azores</option>
          <
    option value="BS">Bahamas</option>
          <
    option value="BH">Bahrain</option>
          <
    option value="BD">Bangladesh</option>
          <
    option value="BB">Barbados</option>
          <
    option value="BY">Belarus</option>
          <
    option value="BE">Belgium</option>
          <
    option value="BZ">Belize</option>
          <
    option value="BJ">Benin</option>
          <
    option value="BM">Bermuda</option>
          <
    option value="BT">Bhutan</option>
          <
    option value="BO">Bolivia</option>
          <
    option value="BA">Bosnia &ampHerzegovina</option>
          <
    option value="BW">Botswana</option>
          <
    option value="BR">Brazil</option>
          <
    option value="VG">British Virgin Islands</option>
          <
    option value="BN">Brunei</option>
          <
    option value="BG">Bulgaria</option>
          <
    option value="BF">Burkina Faso</option>
          <
    option value="BI">Burundi</option>
          <
    option value="KH">Cambodia</option>
          <
    option value="CM">Cameroon</option>
          <
    option value="CA">Canada</option>
          <
    option value="IC">Canary Islands</option>
          <
    option value="CV">Cape Verde</option>
          <
    option value="KY">Cayman Islands</option>
          <
    option value="CF">Central African Republic</option>
          <
    option value="TD">Chad</option>
          <
    option value="CL">Chile</option>
          <
    option value="CN">China</option>
          <
    option value="CX">Christmas Island</option>
          <
    option value="CO">Colombia</option>
          <
    option value="KM">Comoros</option>
          <
    option value="CG">Congo</option>
          <
    option value="CD">Congo Democratic Republic</option>
          <
    option value="CK">Cook Islands</option>
          <
    option value="CR">Costa Rica</option>
          <
    option value="CI">Cote DIvoire</option>
          <
    option value="HR">Croatia</option>
          <
    option value="CU">Cuba</option>
          <
    option value="CY">Cyprus</option>
          <
    option value="CZ">Czech Republic</option>
          <
    option value="DK">Denmark</option>
          <
    option value="DJ">Djibouti</option>
          <
    option value="DM">Dominica</option>
          <
    option value="DO">Dominican Republic</option>
          <
    option value="TL">East Timor</option>
          <
    option value="EC">Ecuador</option>
          <
    option value="EG">Egypt</option>
          <
    option value="SV">El Salvador</option>
          <
    option value="GQ">Equatorial Guinea</option>
          <
    option value="ER">Eritrea</option>
          <
    option value="EE">Estonia</option>
          <
    option value="ET">Ethiopia</option>
          <
    option value="FK">Falkland Islands</option>
          <
    option value="FO">Faroe Islands</option>
          <
    option value="FJ">Fiji</option>
          <
    option value="FI">Finland</option>
          <
    option value="FR">France</option>
          <
    option value="GF">French Guiana</option>
          <
    option value="PF">French Polynesia</option>
          <
    option value="GA">Gabon</option>
          <
    option value="GM">Gambia</option>
          <
    option value="GZ">Gaza</option>
          <
    option value="GE">Georgia</option>
          <
    option value="DE">Germany</option>
          <
    option value="GH">Ghana</option>
          <
    option value="GI">Gibraltar</option>
          <
    option value="GR">Greece</option>
          <
    option value="GL">Greenland</option>
          <
    option value="GD">Grenada</option>
          <
    option value="GP">Guadeloupe</option>
          <
    option value="GT">Guatemala</option>
          <
    option value="GN">Guinea</option>
          <
    option value="GW">Guinea Bissau</option>
          <
    option value="GY">Guyana</option>
          <
    option value="HT">Haiti</option>
          <
    option value="HN">Honduras</option>
          <
    option value="HK">Hong Kong</option>
          <
    option value="HU">Hungary</option>
          <
    option value="IS">Iceland</option>
          <
    option value="IN">India</option>
          <
    option value="ID">Indonesia</option>
          <
    option value="IR">Iran</option>
          <
    option value="IQ">Iraq</option>
          <
    option value="IE">Ireland</option>
          <
    option value="IL">Israel</option>
          <
    option value="IT">Italy</option>
          <
    option value="JM">Jamaica</option>
          <
    option value="JP">Japan</option>
          <
    option value="JO">Jordan</option>
          <
    option value="KZ">Kazakhstan</option>
          <
    option value="KE">Kenya</option>
          <
    option value="KI">Kiribati</option>
          <
    option value="KS">Korea</option>
          <
    option value="KW">Kuwait</option>
          <
    option value="KG">Kyrgyzstan</option>
          <
    option value="LA">Laos</option>
          <
    option value="LV">Latvia</option>
          <
    option value="LB">Lebanon</option>
          <
    option value="LS">Lesotho</option>
          <
    option value="LR">Liberia</option>
          <
    option value="LY">Libya</option>
          <
    option value="LT">Lithuania</option>
          <
    option value="LU">Luxembourg</option>
          <
    option value="MO">Macau</option>
          <
    option value="MK">Macedonia</option>
          <
    option value="MG">Madagascar</option>
          <
    option value="MW">Malawi</option>
          <
    option value="MY">Malaysia</option>
          <
    option value="MV">Maldives</option>
          <
    option value="ML">Mali</option>
          <
    option value="MT">Malta</option>
          <
    option value="MH">Marshall Islands</option>
          <
    option value="MR">Mauritania</option>
          <
    option value="MU">Mauritius</option>
          <
    option value="YT">Mayotte</option>
          <
    option value="MX">Mexico</option>
          <
    option value="FM">Micronesia</option>
          <
    option value="MI">Midway Islands</option>
          <
    option value="MD">Moldova</option>
          <
    option value="MC">Monaco</option>
          <
    option value="MN">Mongolia</option>
          <
    option value="MS">Montserrat</option>
          <
    option value="MA">Morocco</option>
          <
    option value="MZ">Mozambique</option>
          <
    option value="MM">Myanmar</option>
          <
    option value="NA">Nambia</option>
          <
    option value="NR">Nauru</option>
          <
    option value="NP">Nepal</option>
          <
    option value="AN">Netherland Antilles</option>
          <
    option value="NL">Netherlands</option>
          <
    option value="NC">New Caledonia</option>
          <
    option value="NZ">New Zealand</option>
          <
    option value="NI">Nicaragua</option>
          <
    option value="NE">Niger</option>
          <
    option value="NG">Nigeria</option>
          <
    option value="NO">Norway</option>
          <
    option value="OM">Oman</option>
          <
    option value="PK">Pakistan</option>
          <
    option value="PW">Palau Island</option>
          <
    option value="PA">Panama</option>
          <
    option value="PG">Papua New Guinea</option>
          <
    option value="PY">Paraguay</option>
          <
    option value="PE">Peru</option>
          <
    option value="PH">Philippines</option>
          <
    option value="PL">Poland</option>
          <
    option value="PT">Portugal</option>
          <
    option value="PR">Puerto Rico</option>
          <
    option value="QA">Qatar</option>
          <
    option value="RE">Reunion</option>
          <
    option value="RO">Romania</option>
          <
    option value="RU">Russia</option>
          <
    option value="RW">Rwanda</option>
          <
    option value="WS">Samoa</option>
          <
    option value="ST">Sao Tome &ampPrincipe</option>
          <
    option value="SA">Saudi Arabia</option>
          <
    option value="SN">Senegal</option>
          <
    option value="CS">Serbia &ampMontenegro</option>
          <
    option value="SC">Seychelles</option>
          <
    option value="SL">Sierra Leone</option>
          <
    option value="SG">Singapore</option>
          <
    option value="SK">Slovakia</option>
          <
    option value="SI">Slovenia</option>
          <
    option value="SB">Solomon Islands</option>
          <
    option value="SO">Somalia</option>
          <
    option value="ZA">South Africa</option>
          <
    option value="ES">Spain</option>
          <
    option value="LK">Sri Lanka</option>
          <
    option value="KN">St Kitts-Nevis</option>
          <
    option value="LC">St Lucia</option>
          <
    option value="PM">St Pierre &ampMiquelon</option>
          <
    option value="VC">St Vincent &ampGrenadines</option>
          <
    option value="SD">Sudan</option>
          <
    option value="SR">Suriname</option>
          <
    option value="SZ">Swaziland</option>
          <
    option value="SE">Sweden</option>
          <
    option value="CH">Switzerland</option>
          <
    option value="SY">Syria</option>
          <
    option value="TW">Taiwan</option>
          <
    option value="TJ">Tajikistan</option>
          <
    option value="TZ">Tanzania</option>
          <
    option value="TH">Thailand</option>
          <
    option value="TG">Togo</option>
          <
    option value="TO">Tonga</option>
          <
    option value="TT">Trinidad &ampTobago</option>
          <
    option value="TN">Tunisia</option>
          <
    option value="TR">Turkey</option>
          <
    option value="TM">Turkmenistan</option>
          <
    option value="TC">Turks &ampCaicos Is</option>
          <
    option value="TV">Tuvalu</option>
          <
    option value="UG">Uganda</option>
          <
    option value="UA">Ukraine</option>
          <
    option value="AE">United Arab Emirates</option>
          <
    option value="GB">United Kingdom</option>
          <
    option value="US">United States</option>
          <
    option value="UY">Uruguay</option>
          <
    option value="VI">US Virgin Islands</option>
          <
    option value="UZ">Uzbekistan</option>
          <
    option value="VU">Vanuatu</option>
          <
    option value="VE">Venezuela</option>
          <
    option value="VN">Vietnam</option>
          <
    option value="VN">Virgin Islands</option>
          <
    option value="WK">Wake Island</option>
          <
    option value="WF">Wallis &ampFutana Is</option>
          <
    option value="EH">Western Sahara</option>
          <
    option value="YE">Yemen</option>
          <
    option value="ZM">Zambia</option>
          <
    option value="ZW">Zimbabwe</option>
        </
    select>
      <
    tr>
                                  <
    td align="right"><p align="center">Password 
                                    <
    input type="password" name="password" />
                                  </
    p>
                                    <
    p align="center">Hub 
                                      <
    label></label>
                                      <
    select name="hub">
                                        <
    option value="" selected></option
                                      
    >
                                        <
    option value="BRU">Brussels airport</option>
                                        <
    option value="BOM">Chatrapati Shivaji Intl </option>
                                        <
    option value="MAA">Chennai Intl </option>
                                        <
    option value="DEL">Indira Gandhi </option>
                                      </
    select>
        <
    td align="right"><p align="center">Online Flying :
                                      <
    select name="online" id="online">
                                        <
    option value=""></option
                                      
    >
                                        <
    option >IVAO</option>
                                        <
    option>VATSIM</option>
                                      </
    select>
                                    </
    p>
                                      <
    p align="center">ID :
                                        <
    input type="text" name="id" id="id" />
                                      </
    p>
                                      <
    p align="center">Transfer hours 
                                        <
    input type="text" name="transfer" id="transfer" />
          </
    p></td>
                                    <
    td><p align="center">Extra Information 
                                      <
    label>
                                      <
    textarea name="extra" id="extra" cols="45" rows="5"></textarea>
                                      </
    label>
                                    </
    p>
                                    <
    p align="center">
                                      <
    label>                                  </label>
    <
    input type="submit" /></p></td>
                                  </
    tr>
                                    
                                    <
    tr>
                                    <
    td align="right" width="140"><p align="center">:</p></td>
                                    <
    td>&nbsp;</td>
      </
    tr>  
                                    <
    div align="center">
                                      </
    p>
                                    </
    div>
      <
    td>&nbsp;</td>
                                    <
    div align="center">
                                      </
    tr>
                                      </
    p>
                                                                  </
    div>
      <
    tr>
    </
    form>

    </
    form>
    <
    p align="center" class="style1">&nbsp;</p>
    </
    body>
    </
    html
    Insert2.php

    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","root","");
    if (!
    $con)
      {
      die(
    'A problem has occured ' mysql_error());
      }

    mysql_select_db("application"$con);

    $sql="INSERT INTO application (First Name, Last Name, E-mail, Country, Password, Hub, Online, ID, Transfer, Extra)
    VALUES
    ('$_POST[firstname]',' POST[lastname]','$_POST[email]',' $_POST[country]',' $_POST[password]',' $_POST[hub]',' $_POST[online]',' $_POST[id]',' $_POST[transfer]',' $_POST[extra]')"
    ;

    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    echo 
    "1 record toegevoegd";

    mysql_close($con)
    ?>
    Please help

    Regards,
    V
    Last edited by v.c0d3r; 08-29-2007 at 04:37 PM.

  • #2
    New Coder
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    I think your mistake is
    POST[lastname]
    correct would be $_POST[lastname]

  • Users who have thanked alex375 for this post:

    v.c0d3r (08-29-2007)

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    That is wrong as well.

    When using an array index, quote your index.

    PHP Code:
    echo $_POST['lastname']; 
    If you are using this inside of a double quoted string, enclose it like so:

    PHP Code:
    echo "Lastname = {$_POST['lastname']}"

  • Users who have thanked aedrin for this post:

    v.c0d3r (08-29-2007)

  • #4
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks guys but the problem is it says

    PHP Code:
    NoticeUndefined indexonline in E:Program FilesEasyPHP 2.0b1wwwjetvainsert2.php on line 12
    Error
    You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, Last Name, E-mail, Country, Password, Hub, Online, ID, Transfer, Extra) V' at line 1 
    So I don't think it has anything to do with first name.

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    The are some other problems as well.

    For the undefined online error, your form code for that select is not correct. Take a look at it, but at a minimum each option needs a value. This also points out a problem with the form processing code, you should validate each variable from your form once it reaches the server to make sure it contains the expected contents (in this case no variable is set) before blindly putting the values into a database query statement (escaping the data to prevent sql code injection is the minimum you should be doing.)

    The second error (edit: and for the error you just posted) is because you cannot put column names like - First Name, Last Name, and E-mail into a query. You should not have column names that contain spaces or dashes. I recommend that you rename these if they actually have those names. But if you actually do have columns with those names and you don't want to change them, you can enclose them in back-ticks `First Name`, `Last Name`, and `E-mail` every time you reference them in a query.
    Last edited by CFMaBiSmAd; 08-29-2007 at 05:14 PM. Reason: additional post was made while writing this
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    v.c0d3r (08-29-2007)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •