473,416 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 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 2731
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"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
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
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...
0
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
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...

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.