PHP:Unable to post variables from html form to mysql database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sammmista

    #1

    PHP:Unable to post variables from html form to mysql database

    hello experts,
    Plz dont treat this as another newbie query , i did my homework but
    still getting nowhere :( :( :(

    Trying to learn PHP on Fedora core 1 (PHP 4.3,MySQL,HTTPD ).Unable to
    post data from html form to php file(connecting to mysql database and
    inserting into a table) .
    This seemingly simple problem is making me go mad !!! I googled
    extensively and already tried the following

    I enabled " register_global s = On " .... in /etc/php.ini and
    also took used _$POST syntax.



    wot could be the problem .... is it the case that /etc/php.ini file is
    not being read .... how do i know whether this is the default location
    for php.ini?
    Where can i find the PHPRC environment variable (the variable
    responsible for the php.ini default location)

    Is the problem something else .....?

    Plz help me out experts!!!!

    Thx Adv

    Regards,
    Sammista.

    Following is the code ...

    form.html
    ---------
    <HTML>
    <HEAD>
    <TITLE> email entry form </TITLE>
    </HEAD>
    <BODY>

    <P>plz fil the form </P>

    <FORM METHOD="POST" ACTON="form-handler.php">

    NAME: <BR>
    <INPUT TYPE=TEXT NAME="givename" SIZE=25> <BR>
    AGE: <br>
    <INPUT TYPE=TEXT NAME="givenaddr ess" SIZE=25> <BR>

    <INPUT TYPE=SUBMIT>
    </FORM>
    </BODY>
    </HTML>


    form-handler.php
    -----------------
    <HTML>
    <HEAD>
    <TITLE> EMAIL FORM HANDLER </TITLE>
    </HEAD>

    <BODY>

    <?
    mysql_connect(" localhost","roo t") or die("Failure on db connection");

    mysql_select_db ("mydb");

    //$query = " insert into sample(name,add ress)
    values(_$POST['givename'],_$POST['givenaddress'])";


    $query = " INSERT INTO sample SET
    name = '_$POST[givename]',
    address = '_$POST[givenaddress]' ";

    $result = mysql_query($qu ery) or die("Unable to record your info");
    print("result:$ result");
    print("your info has been recorded");

    ?>

    </body>
    </html>
  • jf

    #2
    Re: PHP:Unable to post variables from html form to mysql database

    _$POST ???

    $_POST !!

    or if it isn't the problem try in a file info.php:
    <?php phpinfo(); ?>


    On 29 Sep 2004 12:23:12 -0700
    sammmista@gmail .com (sammmista) wrote:
    [color=blue]
    > hello experts,
    > Plz dont treat this as another newbie query , i did my homework but
    > still getting nowhere :( :( :(
    >
    > Trying to learn PHP on Fedora core 1 (PHP 4.3,MySQL,HTTPD ).Unable to
    > post data from html form to php file(connecting to mysql database and
    > inserting into a table) .
    > This seemingly simple problem is making me go mad !!! I googled
    > extensively and already tried the following
    >
    > I enabled " register_global s = On " .... in /etc/php.ini and
    > also took used _$POST syntax.
    >
    >
    >
    > wot could be the problem .... is it the case that /etc/php.ini file is
    > not being read .... how do i know whether this is the default location
    > for php.ini?
    > Where can i find the PHPRC environment variable (the variable
    > responsible for the php.ini default location)
    >
    > Is the problem something else .....?
    >
    > Plz help me out experts!!!!
    >
    > Thx Adv
    >
    > Regards,
    > Sammista.
    >
    > Following is the code ...
    >
    > form.html
    > ---------
    > <HTML>
    > <HEAD>
    > <TITLE> email entry form </TITLE>
    > </HEAD>
    > <BODY>
    >
    > <P>plz fil the form </P>
    >
    > <FORM METHOD="POST" ACTON="form-handler.php">
    >
    > NAME: <BR>
    > <INPUT TYPE=TEXT NAME="givename" SIZE=25> <BR>
    > AGE: <br>
    > <INPUT TYPE=TEXT NAME="givenaddr ess" SIZE=25> <BR>
    >
    > <INPUT TYPE=SUBMIT>
    > </FORM>
    > </BODY>
    > </HTML>
    >
    >
    > form-handler.php
    > -----------------
    > <HTML>
    > <HEAD>
    > <TITLE> EMAIL FORM HANDLER </TITLE>
    > </HEAD>
    >
    > <BODY>
    >
    > <?
    > mysql_connect(" localhost","roo t") or die("Failure on db connection");
    >
    > mysql_select_db ("mydb");
    >
    > //$query = " insert into sample(name,add ress)
    > values(_$POST['givename'],_$POST['givenaddress'])";
    >
    >
    > $query = " INSERT INTO sample SET
    > name = '_$POST[givename]',
    > address = '_$POST[givenaddress]' ";
    >
    > $result = mysql_query($qu ery) or die("Unable to record your info");
    > print("result:$ result");
    > print("your info has been recorded");
    >
    > ?>
    >
    > </body>
    > </html>[/color]

    Comment

    • Stefan Hegenbart

      #3
      syntax error

      sammmista wrote:[color=blue]
      > hello experts,
      > Plz dont treat this as another newbie query , i did my homework but
      > still getting nowhere :( :( :(
      >
      > Trying to learn PHP on Fedora core 1 (PHP 4.3,MySQL,HTTPD ).Unable to
      > post data from html form to php file(connecting to mysql database and
      > inserting into a table) .
      > This seemingly simple problem is making me go mad !!! I googled
      > extensively and already tried the following
      >
      > I enabled " register_global s = On " .... in /etc/php.ini and
      > also took used _$POST syntax.
      >[/color]
      <snip>

      1.
      it is NOT _$POST but $_POST!

      2.
      to check if your ini is used try the command phpinfo(); you can see your
      settings then - if you change something it should be there too.

      3.
      try to turn error reporting on when developing scripts. do this by
      starting your script with something like
      <?php
      error_reporting (E_ALL);

      that might put out a lot of notices too but helps writing clean code.

      4.
      to find out where php looks for his ini just turn to the manual. i
      prefer using the directive in the apache httpd.conf

      PHPIniDir "/your/path"

      regards
      sh

      --
      "The goal of Computer Science is to build something that will last at
      least until we've finished building it." -- unknown

      Comment

      • Matthias Esken

        #4
        Re: PHP:Unable to post variables from html form to mysql database

        sammmista wrote:
        [color=blue]
        > I enabled " register_global s = On " .... in /etc/php.ini and
        > also took used _$POST syntax.[/color]

        Famous last words: "I don't know how to deactivate this time bomb. I
        better press every button I see."
        [color=blue]
        > wot could be the problem .... is it the case that /etc/php.ini file is
        > not being read .... how do i know whether this is the default location
        > for php.ini?[/color]

        <?php phpinfo(); ?>
        [color=blue]
        > Where can i find the PHPRC environment variable (the variable
        > responsible for the php.ini default location)[/color]

        Somewhere in the source code.
        [color=blue]
        > Is the problem something else .....?[/color]

        Yes, it is.
        [color=blue]
        > <FORM METHOD="POST" ACTON="form-handler.php">[/color]

        "ACTON" should be "action".
        [color=blue]
        > <?[/color]

        You don't want to start this block with "<?". Use "<?php".
        [color=blue]
        > $query = " INSERT INTO sample SET
        > name = '_$POST[givename]',
        > address = '_$POST[givenaddress]' ";[/color]

        Ouch!

        Look up the syntax for INSERT and use $_POST instead of _$POST. If you
        go to your php.ini and set your error_reporting to E_ALL, you might be
        able to find some of those errors by yourself.
        [color=blue]
        > $result = mysql_query($qu ery) or die("Unable to record your info");[/color]

        Not very friendly, eh? Have a look at mysql_error().

        Regards,
        Matthias

        Comment

        Working...