INSERT New Member in to DATABASE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • infoseekar
    New Member
    • Mar 2008
    • 34

    INSERT New Member in to DATABASE

    Hi

    I am trying to create a form for new member to create an account. There are 2 php files. File 1 [nuform.php] is a form where user can enter their data for registration purpose. File 2 [nm.php] sends typed data to database. My problem is I cann't send MySQL query to database to add a new account. Can any one help me.

    file 1 'nuform.php'
    [code=php] <html>

    <title> Member Information</title>
    <?php
    echo
    "<form action='nm.php' method='post'>
    <p>Login Name <input type='text' name='loginName '></p>
    <p>Surname <input type='text' name=Surname'></p>
    <p>First Name <input type='text' name='Firstname '></p>
    <p>Select your Country</p>
    <p><SELECT name="live"></p>
    <p><option value="France"> France</p>
    <p><option value="Spain">S pain</p>
    <p><option value="Australi a">Australia </p>
    <p><option value="United Kingdom">United Kingdom</p>
    </SELECT>
    <p><input type='Submit'></p>
    </form>"

    </html>
    ?>

    file 2 'nm.php'

    <?php


    $user="username ";
    $host="localhos t";
    $password="pass word";
    $database = "test";


    $connection = mysql_connect($ host,$user,$pas sword) //open connection to MySQL
    or die ("couldn't connect to server");


    $db = mysql_select_db ($database,$con nection) // open session to Database
    or die ("Couldn't select database");

    $sql= "INSER INTO member (loginName, Surname, Firstname, live)values '".$_POST['loginName']." ".$_POST['Surname']." ".$_POST ['Firstname']." ".$_POST['live']."'"

    ?>[/code]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    USe code tags to display code on this forum.

    You don't need to insert your own numbers if you do this.

    Thanks.

    Comment

    • infoseekar
      New Member
      • Mar 2008
      • 34

      #3
      Originally posted by markusn00b
      USe code tags to display code on this forum.

      You don't need to insert your own numbers if you do this.

      Thanks.
      thanks for telling me

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        To debug this, echo the $sql statement before the insert so you can check that it is correct and change the mysql_query die part as[php]or die ("Couldn't execute query: ".mysql_error() );[/php] and you will see any error.

        Ronald

        Comment

        • infoseekar
          New Member
          • Mar 2008
          • 34

          #5
          Originally posted by ronverdonk
          To debug this, echo the $sql statement before the insert so you can check that it is correct and change the mysql_query die part as[php]or die ("Couldn't execute query: ".mysql_error() );[/php] and you will see any error.

          Ronald

          Thanks Ronverdonk... Its working now...

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Line 41.
            Use commas between the variables.

            [EDIT]
            Ignore this if you already solved.

            Comment

            • infoseekar
              New Member
              • Mar 2008
              • 34

              #7
              Originally posted by hsriat
              Line 41.
              Use commas between the variables.

              [EDIT]
              Ignore this if you already solved.

              You are right, there were silly mistakes in line 41. Thanks for your help;

              regards

              Infoseekar

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                Originally posted by infoseekar
                You are right, there were silly mistakes in line 41. Thanks for your help;

                regards

                Infoseekar
                Also tell me, is the echo statement at line 5 working?

                Comment

                • infoseekar
                  New Member
                  • Mar 2008
                  • 34

                  #9
                  Originally posted by hsriat
                  Also tell me, is the echo statement at line 5 working?
                  No, I have deleted that statement now..

                  Comment

                  • hsriat
                    Recognized Expert Top Contributor
                    • Jan 2008
                    • 1653

                    #10
                    Originally posted by infoseekar
                    No, I have deleted that statement now..
                    Use \" when you have to send a quote to the html.
                    eg.<SELECT name=\"live\">

                    Comment

                    • infoseekar
                      New Member
                      • Mar 2008
                      • 34

                      #11
                      Originally posted by hsriat
                      Use \" when you have to send a quote to the html.
                      eg.<SELECT name=\"live\">

                      thank you very much.. you have been very helpful..

                      Comment

                      • hsriat
                        Recognized Expert Top Contributor
                        • Jan 2008
                        • 1653

                        #12
                        You are welcome. :)

                        Harpreet

                        Comment

                        Working...