Need help with $_POST

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lovinlazio9
    New Member
    • Nov 2006
    • 2

    Need help with $_POST

    I've just started messing around with PHP and believe it or not its extremely frustrating haha. Anyway, I wanted to make a simple input form that would display the info after submitting it...

    The script is a simple html script, which calls a php script passing
    it the variables which it got by the forms:

    **************H TML doc. named "insert.htm"*** *************** ******

    <html>
    <head>
    <title>HTML Form</title>
    </head>
    <body>
    <form ACTION="script1 .php" METHOD=POST>
    First Name<input TYPE=TEXT NAME="FirstName " SIZE=20><br>
    Last Name <input TYPE=TEXT NAME="LastName" SIZE=20><br>
    E-mail Address <input TYPE=TEXT NAME="Email" SIZE=60><br>
    Comments <textarea NAME="Comments" ROWS=5 COLS=40></textarea><br>
    <input TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!" >
    </form>

    </body>
    </html>



    *************** ************PHP script named "script1.php"** *************** *****

    <HTML>
    <HEAD>
    <TITLE>Form Results</title>
    <BODY>

    <?
    $FirstName = $_POST["FirstName"];
    $LastName = $_POST["LastName"];
    $Email = $_POST["Email"];
    $Comments = $_POST["Comments"];
    ?>


    <?php
    /* This page receives and handles the data generated by "insert.htm l".
    */
    print "Your first name is $_POST["FirstName"].<BR>\n";
    [color=blue]
    print "Your last name is $_POST["LastName"].<BR>\n";
    [color=blue]
    print "Your E-mail is $_POST["Email"].<BR>\n";
    [color=blue]
    print "This is what you had to say:<BR>\n$_POS T["Comments"]<BR>\n";
    [color=blue]
    ?>



    </BODY>
    </HTML>




    I keep getting this error :


    Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/grademyc/public_html/script1.php on line 17


    with line 17 being
    print "Your first name is $_POST["FirstName"].<BR>\n";
    [color=blue]



    i'm new to all this so i'm sure i've made mistakes somewhere...
    please help...thanks!
  • bishwadeep
    New Member
    • Nov 2006
    • 12

    #2
    Answer

    Try this code in your line 17
    <br>I think it is because you did not concat:
    print "Your first name is". $_POST["FirstName"]."<BR>\n";

    If any other error occurred please write me
    Last edited by bishwadeep; Nov 30 '06, 06:00 AM. Reason: add some message

    Comment

    • lovinlazio9
      New Member
      • Nov 2006
      • 2

      #3
      sorry about that, I figured it out last night...REALLY LATE NIGHT!...unfort unately the script isn't putting anything into the MySql database though....it just keeps putting blank entries in the table...any thoughts?

      my code to connect to the database is as follows:


      *************** *************** **********PHP** *************** *************** ************

      <?
      $DBhost = "localhost" ;
      $DBuser = "grademyc_m e";
      $DBpass = "********";
      $DBName = "grademyc_users ";
      $table = "details";
      mysql_connect($ DBhost,$DBuser, $DBpass) or die("Unable to connect to database");

      @mysql_select_d b("$DBName") or die("Unable to select database $DBName");

      $sqlquery = "INSERT INTO $table VALUES('$Name') ";

      $results = mysql_query($sq lquery);

      mysql_close();

      ?>


      *************** *************** *************** *************** *************** **********

      every time i try to update the database through my form is just creates a blank entry which is really annoying...i can obviously update the database via phpMyadmin, but that doesn't help me.....Thanks!
      Danny

      Comment

      • scriptee
        New Member
        • Nov 2006
        • 17

        #4
        Originally posted by lovinlazio9
        sorry about that, I figured it out last night...REALLY LATE NIGHT!...unfort unately the script isn't putting anything into the MySql database though....it just keeps putting blank entries in the table...any thoughts?

        my code to connect to the database is as follows:


        *************** *************** **********PHP** *************** *************** ************

        <?
        $DBhost = "localhost" ;
        $DBuser = "grademyc_m e";
        $DBpass = "********";
        $DBName = "grademyc_users ";
        $table = "details";
        mysql_connect($ DBhost,$DBuser, $DBpass) or die("Unable to connect to database");

        @mysql_select_d b("$DBName") or die("Unable to select database $DBName");

        $sqlquery = "INSERT INTO $table VALUES('$Name') ";

        $results = mysql_query($sq lquery);

        mysql_close();

        ?>


        *************** *************** *************** *************** *************** **********

        every time i try to update the database through my form is just creates a blank entry which is really annoying...i can obviously update the database via phpMyadmin, but that doesn't help me.....Thanks!
        Danny
        Hi ..
        Try using the Insert statement with the table column name like ..

        [PHP]$sqlquery = "INSERT INTO $table ('column_name_1 ','column_name_ 2', ..etc)VALUES('$ value_1, $value_2', ..etc)";[/PHP]

        Hope this will work ...good luck !

        Comment

        • chesko
          New Member
          • Nov 2006
          • 1

          #5
          Hello I think tha you'll better use an echo and to use simple cotes for your variable from POST :

          Code:
          print "Your first name is $_POST["FirstName"].<BR>\n";
          [color=blue]
          becomes
          Code:
          echo "Your first name is $_POST['FirstName'].<BR>\n";
          or

          Code:
          echo 'Your first name is '.$_POST['FirstName'].'<BR>\n';
          bye

          Chesko

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            lovinlazio9: please read the Posting Guidelines at the top of this forum before you post anything else in this forum!

            Especially the part about enclosing posted code within php, code or html tags!

            Ronald :cool:

            Comment

            • moishy
              New Member
              • Oct 2006
              • 104

              #7
              What was the point of doing this:

              $FirstName = $_POST['FirstName'];

              If you're anyways gonna call the $_POST

              print $_POST['FirstName'];

              And not

              print $FirstName;

              Comment

              • TheMadMidget
                New Member
                • Oct 2006
                • 98

                #8
                To continue on from moishy's thought, (onto my own thought)
                Sometimes when I used $_POST['name'] and then again later, it would show up blank. I was like it was erasing it. This was not consistent though, which really threw me for a spin, but it has only happened to me personally with IE 7.newest out.

                Comment

                • kd8con
                  New Member
                  • Dec 2006
                  • 4

                  #9
                  I think I would agree about the variable use rather than using POST. I always save the POSTed data to a variable as I know this will stick and it is easier to type as well.

                  I also think the echo is better than the print - but I don't have a clue why - I think it is just a personal preference.

                  Steve

                  Comment

                  • ronverdonk
                    Recognized Expert Specialist
                    • Jul 2006
                    • 4259

                    #10
                    Originally posted by moishy
                    What was the point of doing this:

                    $FirstName = $_POST['FirstName'];

                    If you're anyways gonna call the $_POST

                    print $_POST['FirstName'];

                    And not

                    print $FirstName;
                    I hope you don't really use the $_POST in that way, moishy! You must have an endless trust in your fellow human beings. Ever heard of cross-site scripting?
                    You should always sanitize your outside data, especially the $_GET and $_POST arrays. They are the main source for XSS attacks.

                    Ronald :cool:

                    Comment

                    Working...