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

Thread: Insert problem

  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    97
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Insert problem

    Trying to insert data into my database from a submitted form

    heres my code

    PHP Code:
    <?php
    include 'connection.php';
    ?>
    <html>
    <head>
        <title> Insert Data Form </title>
    </head>
    <body>
        <form name="insert_data" action="">
            <table>
                <tr>
                <td> Name : <input type="text" name="name" /> </td>
                </tr>
                <tr>
                <td> Age : <input type="text" name="age" /> </td>
                </tr>
                <tr>
                <td> City : <input type="text" name="city" /> </td>
                </tr>
                <tr>
                <td> <input type="submit" name="submit" value="Done" /> </td>
            </table>
        </form>
    </body>

    <?php
    if(isset($_POST['submit'])) {
    $name $_POST['name'];
    $age $_POST['age'];
    $city $_POST['city'];

    $insert "INSERT INTO `test`
    (
    `name`,
    `age`,
    `city`
    ) VALUES(
    '$name',
    '$age',
    '$city')"
    ;

    $insert_data mysql_query($insert) or die(mysql_erorr());
    }

    ?>
    Kevin

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    PHP Code:
    if(isset($_POST['submit'])) {
        
    $name $_POST['name'];
        
    $age $_POST['age'];
        
    $city $_POST['city'];

        
    $insert "INSERT INTO test (name,age,city) VALUES('$name','$age','$city')";

        
    $insert_data mysql_query($insert) or die(mysql_erorr());

    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    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
    Okay so what is happening? Are you getting errors or is it just a blank page? Your query can be on more than one line if you like. It doesn't need to be on one line. Spelling does go a long way though.

    Code:
    $insert_data = mysql_query($insert) or die(mysql_erorr());
    Also I suggest you look into preventing mysql injection.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    New Coder
    Join Date
    Mar 2009
    Posts
    97
    Thanks
    10
    Thanked 0 Times in 0 Posts
    I found out the reason, my form was missing a method="post" thanks anyway

    Kevin


  •  

    Posting Permissions

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