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 6 of 6

Thread: Data insert

  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Data insert

    Hello, the next code is in the reg_index.php and ind_index.php.

    when Im clicking to insert data, its returns empty in db. even doesnt show on the page after clicking submit.Please is there any error?All the rest of code is work only this cant understand the problem.
    The code is.

    reg_index.php
    ///////////////////////////
    <form action="ind_insert.php" >
    .Nombre del Curso
    <input name="name" type="text" id="name" >
    <br>
    Numero_indice
    <input name="number" type="text" id="number">
    <br>
    Numero_programa
    <input name="chapter" type="text" id="chapter" >
    <br>
    <input type="submit" name="Submit" value="ENVIAR">

    </form>
    /////////////////////////////// end of reg_insert.php
    -----------------------------------------------------------------------------
    the ind_insert.php
    <?php
    include'db.php'; //connection to DB

    $name=$_POST['name'];
    $number=$_POST['number'];
    $chapter=$_POST['chapter'];

    $q = "INSERT INTO prog VALUES ('','$name','$number','$chapter')";
    if(!mysql_query($q))
    {
    die(' Error: ' .mysql_error());
    }
    else
    {
    echo"Data Inserted was:";
    echo"<br>";
    echo"<br>";
    echo"$name";
    echo"<br>";
    echo"$number";
    echo"<br>";
    echo"$chapter";

    }
    /////// RETURNS EMPTY AFTER CLICKING ENVIAR //////////

    ?>
    ////////////// end of ind_insert.php

    thank you very very much
    Arsen Khachatryan
    ---------------------------------
    Do you think making money is hard?If so,You haven't clicked yet!!!
    http://www.khaarsen.com/Paid_to_click.php

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Instead of this

    Code:
    $q = "INSERT INTO prog VALUES ('','$name','$number','$chapter')";
    Try this

    Code:
    $q = "INSERT INTO prog VALUES (''name='$name',number='$number',chapter='$chapter')";

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 314 Times in 306 Posts
    Your <form tag is missing a method="post" parameter, so it is using the GET mode by default and the $_POST variables are not being set.
    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.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You need method="post" on your form tag.

    (edit aww shoot I took too long to respond and CFMaBiSmAd beat me to it -- stupid job-related distractions)

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by masterofollies View Post
    Instead of this

    Code:
    $q = "INSERT INTO prog VALUES ('','$name','$number','$chapter')";
    Try this

    Code:
    $q = "INSERT INTO prog VALUES (''name='$name',number='$number',chapter='$chapter')";
    And don't use that as it will error out. You also have an unneeded comma.
    PHP Code:
    $q "INSERT INTO prog VALUES ('$name','$number','$chapter')"
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Well it works on my website just fine.


  •  

    Tags for this Thread

    Posting Permissions

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