By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,715 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,715 IT Pros & Developers. It's quick & easy.

Help With if/else in PHP/MySQL

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I noticed that Message-ID:
<fb**************************@posting.google.com > from spacemancw
contained the following:
Now this was for PHP 3. Is that fact that I have PHP 4 a problem. Is
there a change I should make?

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/
Jul 17 '05 #2

P: n/a
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("$FormText or whatever the textbox name is"). If the form uses
GET method, the collection is $_GET("")
On 12 Mar 2004 09:36:52 -0800, sp********@yahoo.com (spacemancw)
wrote:
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


Jul 17 '05 #3

P: n/a
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
sd******@hotmail.com wrote in message news:<q5********************************@4ax.com>. ..
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("$FormText or whatever the textbox name is"). If the form uses
GET method, the collection is $_GET("")
On 12 Mar 2004 09:36:52 -0800, sp********@yahoo.com (spacemancw)
wrote:
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

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.