473,503 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help With if/else in PHP/MySQL

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
3 1937
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2938
by: Erich Trowbridge | last post by:
Has anybody seen this tool? It is awesome. check out http://vw.vermeer.org/ . It's a php front end for large-scale syslog deployments. It makes managing syslog in large networks a snap. The idea...
6
3385
by: Dal | last post by:
Help! I'm trying to get a login script to work. I get this error message MySQL Login Error: You have an error in your SQL syntax near ''jvsd0001_customers` WHERE cust_name='testuser' AND...
0
2081
by: Dafella | last post by:
The following is code from Xeoport. It is suppose to access my pop3 account and load email into Mysql database. It's not inserting and there is no log or anything to tell me why. Here is the...
3
2198
by: Trogdor | last post by:
I set up a server on an AMD 650 machine running gentoo linux. I installed Apachie 2, MySQL 4.1 and PHP 4.3.11 I use another computer on my local net (192.168.0.x) to access the server as a...
2
3854
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
4
2281
by: Mark | last post by:
the Following bit of code doesn't work. It seems to respond to the second, starting with 'add iif statement for Good Practice', but not to the first, starting 'add iif statement for archived' ...
1
1950
by: terryspanky | last post by:
----------------------Below are all the codes don't have errors---- The only problem I have is when I Delete, I'ts not deleting the subject that I click. I want to use the above codes to modify the...
3
1354
by: coopst1 | last post by:
below is my almost completed code. I need help trying to figure out how to display to a textarea all the data I have in phpMyAdmin (database). I have two methods near the bottom called itemResults()...
0
5518
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
2761
by: DarkGiank | last post by:
Hi, im new to csharp and im trying to create a class that can change the application database without no rewriting all connection code... but cause some reason it is not working... it tells me that...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.