Help With if/else in PHP/MySQL

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

    Help With if/else in PHP/MySQL

    I'm reading an article on MySQL/PHP at
    Lycos, Inc., is a web search engine and web portal established in 1994, spun out of Carnegie Mellon University. Lycos also encompasses a network of email, webhosting, social networking, and entertainment websites.


    It's very good for me starting out but I have a question.

    I'm using OS X Panther 10.3.2

    MySQL 4.0.15

    PHP 4.3.2 (cli) (built: Sep 13 2003 22:04:20)
    Copyright (c) 1997-2003 The PHP Group
    Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies

    Apache/1.3.29 (Darwin)


    Following the tutorial things are looking good up until "Throw in Some
    Forms" in Lesson 2.
    Lycos, Inc., is a web search engine and web portal established in 1994, spun out of Carnegie Mellon University. Lycos also encompasses a network of email, webhosting, social networking, and entertainment websites.

    There is a form as follows

    .....snip...... ........

    if ($submit) {

    // process form

    while (list($name, $value) = each($HTTP_POST _VARS)) {

    echo "$name = $value<br>\n";

    }

    } else{

    // display form

    .....snip...... ........

    and the next form after that also.
    I pull up the forms which I have called fpage2.php and fpage3.php
    In the first form fpage2.php, it should display the input fields the
    first time you access it. Then when you fill it in, 'submit' now has a
    value, so the return page should list the values just entered. It
    doesn't, it just shows the form again.

    In the next form fpage3.php, it should display the input fields the
    first time you access it. Then when you fill it in, 'submit' now has a
    value, so the return page should display "Thank you! Information
    entered." and the data should be inserted into mydb. It doesn't, it
    just shows the form again.

    So it's as if the 'if/else' statement doesn't get a positive with the
    if ($submit) {
    and so it just moves on to the 'else'.

    I just copied and pasted ther forms into a file using VI on the
    command line and didn't edit them in any way.

    Now this was for PHP 3. Is that fact that I have PHP 4 a problem. Is
    there a change I should make?

    Any help would be appreciated.

    Thanx

    rmc
  • Geoff Berrow

    #2
    Re: Help With if/else in PHP/MySQL

    I noticed that Message-ID:
    <fbb1f69b.04031 20936.5a5e9bba@ posting.google. com> from spacemancw
    contained the following:
    [color=blue]
    >Now this was for PHP 3. Is that fact that I have PHP 4 a problem. Is
    >there a change I should make?[/color]
    You probably have register _globals = off

    Try
    if ($_POST['submit'])
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • sdeyoreo@hotmail.com

      #3
      Re: Help With if/else in PHP/MySQL

      I had trouble with thier tutorials also. They seem to left out
      $_POST(" "). The submit button and all stuff from a form are in the
      $_POST coolection, meaning the right way to say it is
      $_POST("$submit ") or if it was text from a textbox, it woyuld be in
      $_POST("$FormTe xt or whatever the textbox name is"). If the form uses
      GET method, the collection is $_GET("")
      On 12 Mar 2004 09:36:52 -0800, spacemancw@yaho o.com (spacemancw)
      wrote:
      [color=blue]
      >I'm reading an article on MySQL/PHP at
      >http://hotwired.lycos.com/webmonkey/...tw=programming
      >
      >It's very good for me starting out but I have a question.
      >
      >I'm using OS X Panther 10.3.2
      >
      >MySQL 4.0.15
      >
      >PHP 4.3.2 (cli) (built: Sep 13 2003 22:04:20)
      >Copyright (c) 1997-2003 The PHP Group
      >Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies
      >
      >Apache/1.3.29 (Darwin)
      >
      >
      >Following the tutorial things are looking good up until "Throw in Some
      >Forms" in Lesson 2.
      >http://hotwired.lycos.com/webmonkey/...tw=programming
      >There is a form as follows
      >
      > .....snip...... ........
      >
      >if ($submit) {
      >
      > // process form
      >
      > while (list($name, $value) = each($HTTP_POST _VARS)) {
      >
      > echo "$name = $value<br>\n";
      >
      > }
      >
      >} else{
      >
      > // display form
      >
      > .....snip...... ........
      >
      >and the next form after that also.
      >I pull up the forms which I have called fpage2.php and fpage3.php
      >In the first form fpage2.php, it should display the input fields the
      >first time you access it. Then when you fill it in, 'submit' now has a
      >value, so the return page should list the values just entered. It
      >doesn't, it just shows the form again.
      >
      >In the next form fpage3.php, it should display the input fields the
      >first time you access it. Then when you fill it in, 'submit' now has a
      >value, so the return page should display "Thank you! Information
      >entered." and the data should be inserted into mydb. It doesn't, it
      >just shows the form again.
      >
      >So it's as if the 'if/else' statement doesn't get a positive with the
      >if ($submit) {
      >and so it just moves on to the 'else'.
      >
      >I just copied and pasted ther forms into a file using VI on the
      >command line and didn't edit them in any way.
      >
      >Now this was for PHP 3. Is that fact that I have PHP 4 a problem. Is
      >there a change I should make?
      >
      >Any help would be appreciated.
      >
      >Thanx
      >
      >rmc[/color]

      Comment

      • spacemancw

        #4
        Re: Help With if/else in PHP/MySQL

        Guys

        thanx a million ... this is what works

        ......snip..... .........
        if ($_POST['submit']) {

        // process form
        $db = mysql_connect(" localhost", "root");

        mysql_select_db ("mydb", $db);

        $insert_data = "INSERT INTO employees (first, last, address,
        position ) VALUES ( '$_POST[first]', '$_POST[last]',
        '$_POST[address]', '$_POST[position]' );";

        $result = mysql_query( $insert_data, $db );
        ......snip..... .........

        Took me a bit to figure this out with trial and error and of course
        your help.
        Above you see in the INSERT INTO I have the values in this format

        '$_POST[first]'

        Based on the info in your reply I was trying

        $_POST("$first" )
        '$_POST("$first ")'
        '$_POST('$first ')'
        and so on .. until I finally got it to work
        But thanx for putting me on the right track.
        I'm sure I'll be back here again.

        Thanx

        Roger


        sdeyoreo@hotmai l.com wrote in message news:<q55450p6d t17an90vh09s8ja luqeq681qd@4ax. com>...[color=blue]
        > I had trouble with thier tutorials also. They seem to left out
        > $_POST(" "). The submit button and all stuff from a form are in the
        > $_POST coolection, meaning the right way to say it is
        > $_POST("$submit ") or if it was text from a textbox, it woyuld be in
        > $_POST("$FormTe xt or whatever the textbox name is"). If the form uses
        > GET method, the collection is $_GET("")
        > On 12 Mar 2004 09:36:52 -0800, spacemancw@yaho o.com (spacemancw)
        > wrote:
        >[color=green]
        > >I'm reading an article on MySQL/PHP at
        > >http://hotwired.lycos.com/webmonkey/...tw=programming
        > >
        > >It's very good for me starting out but I have a question.
        > >
        > >I'm using OS X Panther 10.3.2
        > >
        > >MySQL 4.0.15
        > >
        > >PHP 4.3.2 (cli) (built: Sep 13 2003 22:04:20)
        > >Copyright (c) 1997-2003 The PHP Group
        > >Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies
        > >
        > >Apache/1.3.29 (Darwin)
        > >
        > >
        > >Following the tutorial things are looking good up until "Throw in Some
        > >Forms" in Lesson 2.
        > >http://hotwired.lycos.com/webmonkey/...tw=programming
        > >There is a form as follows
        > >
        > > .....snip...... ........
        > >
        > >if ($submit) {
        > >
        > > // process form
        > >
        > > while (list($name, $value) = each($HTTP_POST _VARS)) {
        > >
        > > echo "$name = $value<br>\n";
        > >
        > > }[/color]
        >[color=green]
        > >} else{
        > >
        > > // display form
        > >
        > > .....snip...... ........
        > >
        > >and the next form after that also.
        > >I pull up the forms which I have called fpage2.php and fpage3.php
        > >In the first form fpage2.php, it should display the input fields the
        > >first time you access it. Then when you fill it in, 'submit' now has a
        > >value, so the return page should list the values just entered. It
        > >doesn't, it just shows the form again.
        > >
        > >In the next form fpage3.php, it should display the input fields the
        > >first time you access it. Then when you fill it in, 'submit' now has a
        > >value, so the return page should display "Thank you! Information
        > >entered." and the data should be inserted into mydb. It doesn't, it
        > >just shows the form again.
        > >
        > >So it's as if the 'if/else' statement doesn't get a positive with the
        > >if ($submit) {
        > >and so it just moves on to the 'else'.
        > >
        > >I just copied and pasted ther forms into a file using VI on the
        > >command line and didn't edit them in any way.
        > >
        > >Now this was for PHP 3. Is that fact that I have PHP 4 a problem. Is
        > >there a change I should make?
        > >
        > >Any help would be appreciated.
        > >
        > >Thanx
        > >
        > >rmc[/color][/color]

        Comment

        Working...