Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Junior Member newchance's Avatar
    Join Date
    Feb 2007
    Posts
    15
    Member #
    14865
    Don't know where to post my question - so will add it in here........
    I'm a very very newbie to the php & SQL things.......
    I have tried to put up a simple form on my webpage (in test mode of course)
    I managed to do the creation of database plus the table
    but then it goes wrong!
    i.e. when I typed my name etc into the webpage form,
    I got the notice that the post was submitted.

    Then when checking the database - I found the addition (incremental adds of IDs) but no other details........ so it seems I have something wrong?

    Would somebody care to tell me what I have to change in this very very simple script? Thank you in advance,
    newchance

    Form reads like this:
    HTML Code:
    <html>
    <body>
    <form action="insert.php" method="post">
    <table style="width: 50%">
        <tr>
            <td class="style1"><strong>Firstname:</strong></td>
            <td><span> <input type="text" name="firstname0" /></span></td>
        </tr>
        <tr>
            <td class="style2"><strong>Lastname:</strong></td>
            <td><span> <input type="text" name="lastname0" /></span></td>
        </tr>
        <tr>
            <td class="style2"><strong>Date:&nbsp;&nbsp;&nbsp; </strong></td>
            <td><span> <input type="text" name="date0" /></span></td>
        </tr>
        <tr>
            <td class="style2"><strong>Email: </strong></td>
            <td><span><input type="email" name="email0" /></span></td>
        </tr>
        <tr>
            <td class="style2"><strong>Country: </strong></td>
            <td><span> <input type="text" name="country0" /></span></td>
        </tr>
    </table>
    <span>
    <input type="submit" value="Subscribe to News on our products" name="submit" /></span>
    </form>
    
    </body>
    </html>
    insert.php reads like this:
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","xxxxx","xxxx");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("member"$con);

    $sql="INSERT INTO person (FirstName, LastName, Date, Email, Country)
    VALUES
    ('
    $_POST[firstname]','$_POST[lastname]','$_POST[date]','$_POST[email]', '$_POST[country]')";

    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    mysql_close($con)
    ?>
    Protect your identity - Enroll here

  2.  

  3. #2
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    The "0"s in the end of each form item's name means that the $_POST array has those keys (and values). So you should do $_POST['firstname0'].
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  4. #3
    Junior Member newchance's Avatar
    Join Date
    Feb 2007
    Posts
    15
    Member #
    14865
    Thank you Steax,
    silly me, just overlooked the fact.......

    Is there anything I should add - to avoid trouble with different browsers?
    Tried to find it in the tutorials but........

    newchance
    Protect your identity - Enroll here

  5. #4
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    Browsers should probably behave the same. PHP handles things the same, unregarding browsers (although if there were browser problems, you can detect the browser from PHP).


    I think you're set to go. But I do suggest using CSS for laying out your form instead of tables.
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  6. #5
    Junior Member newchance's Avatar
    Join Date
    Feb 2007
    Posts
    15
    Member #
    14865
    Quote Originally Posted by Steax
    Browsers should probably behave the same. PHP handles things the same, unregarding browsers (although if there were browser problems, you can detect the browser from PHP).


    I think you're set to go. But I do suggest using CSS for laying out your form instead of tables.
    Thx again Steax,

    My test was successful in my test domain........
    I tried to add a few things and moved to my real domain,
    and now I don't get it to work - again.....lol

    What's wrong with my redirection trial? This file is insert.php

    <?php
    ob_start();
    $con = mysql_connect("localhost","xxxxxxx","xxxxxxx");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("member", $con);

    $sql="INSERT INTO person (firstname,lastname,product, date, email, country)
    VALUES
    ('$_POST[firstname]','$_POST[lastname]','$_POST[product]','$_POST[date]','$_POST[email]', '$_POST[country]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }

    mysql_close($con)

    header ("refresh: 5; index.html");
    echo "Thanks $firstname, your subscription was successful";
    ob_end_flush();

    ?>

    Was hoping to get this working - before I get to the CSS form creation....
    I'm a newbie there too.....lol
    newchance
    Protect your identity - Enroll here

  7. #6
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    I'm not an expert in PHP and I'm not very experienced with the header() function... but I do think that you should just use location: something.php instead.
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:56 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com