473,799 Members | 3,810 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 1952
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("$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, sp********@yaho o.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******@hotmai l.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("$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, sp********@yaho o.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
2969
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 is to fifo pipe network syslog into a MySQL database backend. The php scripts reference the database, and print stuff to the screen. My Info -> RH9.0 , MySQL 4.0.14, apache1.3.28 I have successfully gotten everything installed, compiled, etc....
6
3425
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 cust_pass='test123'' at line 1 I'm using a database called test here is mysql table:
0
2097
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 page. http://www.dafella.com/xeoport/ The original coder left no contact info. The reason I think it's the code is because of another issue.
3
2212
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 client. MySQL works perfectly. I have created and queried databases with no problem. Apachie 2 appears to work with no problem. I can call up web pages in the expected maner.
2
3901
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 http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it is a server problem but was told it is not possible, therefore assuming it is a client script problem? the script works last time...
4
2298
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' Help me to sort this out, it has taken me almost a week to wade through and it still won't work. Select Case Forms("frmForce").OpenArgs
1
1969
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 code in "line 168"and in line"393" <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <%Option Explicit%> <% Dim strCourseCode Dim strSubjectCode Dim strSubjectName
3
1380
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() and productResults() with the body of them commented out so it will compile. What is commented out is the way I think it should work but it is not working. If anyone would like to see entire code I would be glad to email for it will not let me post...
0
5577
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
1
2774
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 im not creating the object but im doing it,,, please help im a newbie to c# using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SQLite; using MySql.Data; using MySql.Data.MySqlClient; using...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6808
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.