472,959 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,959 software developers and data experts.

Can anyone tell me why this wont work??

I am trying to check and see if a field is posted or not, if not
posted then assign $location which is a session variable to
$location_other. If it is posted then just assign it to
$location_other

I keep getting "Notice: Undefined index: location_other" referring to
(!($_POST['location_other'))
if (!($_POST['location_other'])) {
$location_other = $location;
}
else
if ($_POST['location_other'])
$location_other = $_POST['location_other'];

THANKS!!!
-Scott
Jul 16 '05 #1
5 2679
Rather than use
(!($_POST['location_other']))
use
(!array_key_exists("location_other", $_POST))
which checks whether there is a variable named location_other in the _POST
array.

Mike
PS haven't checked this code, but should be OK
"Scott D" <dk*****@yahoo.com> wrote in message
news:fe*************************@posting.google.co m...
I am trying to check and see if a field is posted or not, if not
posted then assign $location which is a session variable to
$location_other. If it is posted then just assign it to
$location_other

I keep getting "Notice: Undefined index: location_other" referring to
(!($_POST['location_other'))
if (!($_POST['location_other'])) {
$location_other = $location;
}
else
if ($_POST['location_other'])
$location_other = $_POST['location_other'];

THANKS!!!
-Scott

Jul 16 '05 #2
With total disregard for any kind of safety measures
dk*****@yahoo.com (Scott D) leapt forth and uttered:
I am trying to check and see if a field is posted or not, if not
posted then assign $location which is a session variable to
$location_other. If it is posted then just assign it to
$location_other

I keep getting "Notice: Undefined index: location_other"
referring to (!($_POST['location_other'))
if (!($_POST['location_other'])) {
$location_other = $location;
}
else
if ($_POST['location_other'])
$location_other = $_POST['location_other'];

THANKS!!!
-Scott


Its because you're using an array key ($_POST['location_other'])
which hasn't been declared.

The easiest way to get around this is to use
error_reporting(E_ALL ^ E_NOTICE), this will disregard 'Notice'
errors but keep all others.

Either that or use if(!empty($_POST['location_other'])) rather than
just testing for true or false.

--
There is no signature.....
Jul 16 '05 #3
Joshua Ghiloni wrote:
Scott D wrote:
I am trying to check and see if a field is posted or not, if not
posted then assign $location which is a session variable to
$location_other. If it is posted then just assign it to
$location_other

I keep getting "Notice: Undefined index: location_other" referring to
(!($_POST['location_other'))
if (!($_POST['location_other'])) {
$location_other = $location;
}
else if ($_POST['location_other'])
$location_other = $_POST['location_other'];

THANKS!!!
-Scott

Read your errors :) That's saying that the index doesn't exist, and
you're checking to see if it's true. change your condition to

if (isset($_POST['location_other']))

and all should be well with the world.


I would add that your code is somewhat messy... Your conditional goes
like this :

if false then
doSomething()
else if true then
doSomethingElse
end if

don't you think the second test is useless ? And given the variables
names, it would also seems more readable to first handle the true part.

Try :

if (isset($_POST['location_other']))
{
$location_other = $_POST['location_other']
}
else
{
$location_other = $location;
}

Clearer, isn't it ?-) Reading this, you see more clearly that $location
is a default value for $location_other...

Bruno


Jul 16 '05 #4
dk*****@yahoo.com (Scott D) wrote in message news:<fe*************************@posting.google.c om>...
I keep getting "Notice: Undefined index: location_other" referring to
(!($_POST['location_other'))
if (!($_POST['location_other'])) {
$location_other = $location;
}
else
if ($_POST['location_other'])
$location_other = $_POST['location_other'];


I tend to use the following construct at the top of my pages
instead...

$location_other = isset ($_POST['location_other']) ?
$_POST['location_other'] : $location;

It's only one line and makes it easier when you've got 20 form
variables coming in. It also forces default values to be set, which
can be useful during the next stage, which is when I validate the form
variables before doing any processing upon them.
Jul 16 '05 #5

"Paul Liversidge" <pa*************@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...

I tend to use the following construct at the top of my pages
instead...

$location_other = isset ($_POST['location_other']) ?
$_POST['location_other'] : $location;

It's only one line and makes it easier when you've got 20 form
variables coming in. It also forces default values to be set, which
can be useful during the next stage, which is when I validate the form
variables before doing any processing upon them.

Jul 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Oliver Spiesshofer | last post by:
Hi, I have a script that calls an fopen() on an external URL. I can run the script from the server as an url fine. When however the script should be run from crontab, it does not work. I get ...
19
by: Allen Thompson | last post by:
sorry for the simple question, haven't done this in a while. when I use the following script it keeps displaying the value of "x" like a string. for example, if I type the number 7 in the prompt,...
7
by: Skc | last post by:
Hullo Just like to check whether anyone has tried RentACoder. I intend to farm out a small job that must use C#, WinForms, ADO.Net for around US$400, but don't know whether RentACoder is...
2
by: Tony | last post by:
I found similar code for encoding/decoding strings in VB which works fine. However I wanted to use it in a C# projected and can't get it to work. When it executes the TransformFinalBlock() call at...
5
by: Mr Newbie | last post by:
Debug.Assert( False, "Why wont I display ??") I am trying to use this in my code but it wont display. The app is running on my local machine and the above code under a button click event. What...
5
by: tony | last post by:
I'm using PHP 5 on Win-98 command line (ie no web server involved) I'm processing a large csv file and when I loop through it I can process around 275 records per second. However at around...
13
by: nigel.t | last post by:
Using linux <?php exec("/bin/tar -cvzf myfile.tgz /home/",$arrayout,$returnval); ?> or perhaps try it on your system and tell me if it does/doesnt and what your linux is? I've also tried
1
by: Jia Lu | last post by:
Hello I have a program that can telnet to a host. But I cannot understand from part, can anyone explain it to me? Thank you very much. import sys, posix, time
0
by: watashi | last post by:
Hello, This is on socket. i m using tcpclient and tcplistener task is when the "Active " button is pressed according to user choice tool should work as server or client. when "Inactive"...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.