Results 1 to 4 of 4
  1. #1

    Default need help with my php code


    Im new with php and im trying to insert data into mysql databas... but i get an error...

    need help!

    here is my code:

    <?php
    require ('Connection.php');

    //$con = mysql_connect("localhost", "root","") or die('Cant connnect '.mysql_error());
    //mysql_select_db("mydb",$con);

    //$LNAME=$_POST[txtLname];
    //$FNAME=$_POST[txtFname];
    //$MINITIAL=$_POST[txtMinitial];
    //$BIRTHDATE=NULL;
    //$birthdate=($_POST[month],$_POST[day],$_POST[year]);
    //$ADD1=$_POST[txtadd1];
    //$ADD2=$_POST[txtadd2];
    //$COUNTRY=$_POST[txtcountry];
    //$CONTACT=$_POST[txtcontact];
    //$EMAIL=$_POST[txtemail];

    $result = mysql_query("INSERT INTO register (CUSTOMER_NO,LNAME,FNAME,MINITIAL,BIRTHDATE,ADD1,A DD2,COUNTRY,CONTACT_NO,EMAIL)
    VALUES(NULL,'$_POST[txtLname]','$_POST[txtFname]','$_POST[txtMinitial]',NULL,'$_POST[txtadd1]','$_POST[txtadd2]','$_POST[txtcountry]','$_POST[txtcontact]','$_POST[txtemail]')",$con);

    if(!$result)
    {
    //header("Location:http://localhost/PhpProject/Index/register.php");
    }

    // elseif(empty($_POST['txtLname']))

    // {

    // header("Location:http:");

    // }


    mysql_close($con)

    ?>



    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="Reg_Css.css" />
    </head>
    <body bgcolor="#000000">
    <div id="container">
    <div id="header">
    <h1>
    <img src="../pix/logo.jpg" />
    </h1>
    </div>
    <div id="navigation">
    <ul>
    <li><a href="../home.php">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Contact us</a></li>
    </ul>
    </div>


    <div align="left" id="content">
    <h2>
    Register
    </h2>
    <p>&nbsp;</p>

    <p>
    <form name="register" action="register.php" method="post">
    <p>&nbsp;<label><span class="style1"> Last Name:</span></label>
    <input name="txtLname" type="text" id="txtLname"><label><span class="style1"> First Name:</span></label> <input name="txtFname" type="text" id="txtFname">
    <label><span class="style1"> Middle Initial:</span></label> <input name="txtMinitial" type="text" size="1" maxlength="1" id="txtMinitial"></p>
    <p>&nbsp;<label><span class="style1"> Birthdate:</span></label>
    <select name="month" size="1">
    <option> </option>
    <option>January</option>
    <option>Febuary</option>
    <option>March</option>
    <option>April</option>
    <option>May</option>
    <option>June</option>
    <option>July</option>
    <option>August</option>
    <option>September</option>
    <option>October</option>
    <option>November</option>
    <option>December</option>
    </select>
    <select name="day" size="1">
    <option> </option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    <input name="year" type="text" size="5" maxlength="4"/>
    </p>
    <p>&nbsp; <label><span class="style1"> Address1:</span></label> <input name="txtadd1" type="text" size="80" id="txtadd1"></p>
    <p>&nbsp; <label><span class="style1"> Address2:</span></label> <input name="txtadd2" type="text" size="80" id="txtadd2"></p>
    <p>&nbsp; <label><span class="style1"> Country:</span></label>
    <select name="txtcountry" size="1" id="txtcountry">
    <option>-----------</option>
    <option>Philippines</option>
    <option>North America</option>
    <option>Canada</option>
    </select>
    <span class="style3">(<span class="style5">Optional</span>)</span>
    </p>
    <p>&nbsp;<label><span class="style1"> Contact No:</span></label> <input name="txtcontact" type="text" id="txtcontact"></p>
    <p>&nbsp;<label><span class="style1"> Email:</span></label> <input name="txtemail" type="text" id="txtemail"></p>
    <p>&nbsp;<label><span class="style1"> Username:</span></label> <input name="txtuser" type="text" id="txtuser"></p>
    <p>&nbsp;<label><span class="style1"> Password:</span></label>
    <input name="txtpass" type="password" maxlength="11" id="txtpass">
    <span class="style3">(<span class="style5">Max characters 11</span>)</span></p>

    <p>&nbsp;
    &nbsp;
    &nbsp;
    &nbsp;
    &nbsp;
    &nbsp;

    &nbsp;
    &nbsp;
    &nbsp;
    &nbsp;
    &nbsp;

    &nbsp;
    &nbsp;
    &nbsp;
    &nbsp;
    &nbsp;

    &nbsp;
    &nbsp;
    &nbsp;
    &nbsp;
    <input name="submit" type="submit" value="submit"></p>
    <p>&nbsp;</p>


    </form>


    </div>


    <div id="footer">
    Copyright © Snoop Dog and Friends, 2011
    </div>
    </div>


    </body>


    </html>

  2. #2
    check imo insert string...

    "A DD2"...

    you also take out the "$con" connection string sa imo query function.. Probably it would be safe to do it this way

    $result = mysql_query("INSERT INTO register (CUSTOMER_NO,LNAME,FNAME,MINITIAL,BIRTHDATE,ADD1,A DD2,COUNTRY,CONTACT_NO,EMAIL)
    VALUES (NULL,'$_POST[txtLname]','$_POST[txtFname]','$_POST[txtMinitial]',NULL,'$_POST[txtadd1]','$_POST[txtadd2]','$_POST[txtcountry]','$_POST[txtcontact]','$_POST[txtemail]')");

    Also, check your table fields whether CUSTOMER_NO accepts NULL values, if its a primary key, probably SQL would return errors telling you that the field does not accept null values...
    Last edited by psyche54; 10-15-2010 at 08:34 AM.

  3. #3
    Junior Member
    Join Date
    Jul 2007
    Gender
    Male
    Posts
    200
    bai customer number nmo bai ang setup guro ana kay auto increment na sa database ayaw nalang na e NULL din remove nalang sa fields ug values.. like this

    $result = mysql_query("INSERT INTO register (LNAME,FNAME,MINITIAL,BIRTHDATE,ADD1,A DD2,COUNTRY,CONTACT_NO,EMAIL)
    VALUES('$_POST[txtLname]','$_POST[txtFname]','$_POST[txtMinitial]',NULL,'$_POST[txtadd1]','$_POST[txtadd2]','$_POST[txtcountry]','$_POST[txtcontact]','$_POST[txtemail]')",$con) or die(mysql_error());
    to help you debug sad butange ug mysql_error() tan-awa ako gi quote aron naa ka idea y nag error

  4. #4
    can you post your TABLE structure...

  5.    Advertisement

Similar Threads

 
  1. Help with my php code
    By senpai91 in forum Programming
    Replies: 37
    Last Post: 02-17-2012, 10:53 AM
  2. Need help with my xda mini II
    By dragoneer in forum Gizmos & Gadgets (Old)
    Replies: 2
    Last Post: 09-25-2007, 08:13 AM
  3. NEED help with my N70
    By shogunfreak in forum Gizmos & Gadgets (Old)
    Replies: 0
    Last Post: 06-12-2007, 11:32 AM
  4. need help with my modem...
    By vicdins in forum Computer Hardware
    Replies: 0
    Last Post: 01-02-2007, 04:43 PM
  5. Need help with my busted Geforce Fx5200 Fan
    By ungas in forum Computer Hardware
    Replies: 4
    Last Post: 10-02-2006, 06:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top