473,398 Members | 2,120 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,398 software developers and data experts.

Simple If Statement

How come this doesn't work?

What am I doing wrong?

$type = $_GET['functionType'];

if ($type == 'Add'){
$AddSQL = "INSERT INTO...";
echo $AddSQL;
}elseif ($type == 'Update'){
$UpdateSQL = "Update ...";
echo $UpdateSQL;
}elseif ($type == 'Delete'){
$DelSQL = "DELETE FROM ...";
echo $DelSQL;
}

Thanks

Jan 2 '07 #1
6 1347

print_r($_GET);

See if 'functionType' is set, and one of those values. You could
also do:

if ( isset($_GET['functionType']) ) {
$type = $_GET['functionType'];
// the rest of the if stuff
}
else {
die ("Error, functionType is not in GET");
}
/m

Jeff Vaccaro wrote:
How come this doesn't work?

What am I doing wrong?

$type = $_GET['functionType'];

if ($type == 'Add'){
$AddSQL = "INSERT INTO...";
echo $AddSQL;
}elseif ($type == 'Update'){
$UpdateSQL = "Update ...";
echo $UpdateSQL;
}elseif ($type == 'Delete'){
$DelSQL = "DELETE FROM ...";
echo $DelSQL;
}

Thanks
Jan 2 '07 #2
Jeff Vaccaro wrote:
How come this doesn't work?

What am I doing wrong?

$type = $_GET['functionType'];
Print $type and check the case; 'add' and 'Add' are two different things the
way you compare them.

If the case indeed is the problem try the following function:

http://www.php.net/manual/en/function.strcasecmp.php
JW
Jan 2 '07 #3
Apparently there was a rogue space in the $_GET. I trimmed that and
now it appears to be working!

Thanks.
Janwillem Borleffs wrote:
Jeff Vaccaro wrote:
How come this doesn't work?

What am I doing wrong?

$type = $_GET['functionType'];

Print $type and check the case; 'add' and 'Add' are two different things the
way you compare them.

If the case indeed is the problem try the following function:

http://www.php.net/manual/en/function.strcasecmp.php
JW
Jan 2 '07 #4
Print $type and check the case; 'add' and 'Add' are two different things the
way you compare them.
you could also use strtolower to have just lower cases to compare
Jan 2 '07 #5
On Tue, 02 Jan 2007 05:47:20 -0800, Jeff Vaccaro wrote:
How come this doesn't work?

What am I doing wrong?

$type = $_GET['functionType'];

if ($type == 'Add'){
$AddSQL = "INSERT INTO...";
echo $AddSQL;
}elseif ($type == 'Update'){
$UpdateSQL = "Update ...";
echo $UpdateSQL;
}elseif ($type == 'Delete'){
$DelSQL = "DELETE FROM ...";
echo $DelSQL;
}

you should make your code more readable (for yourself)
have a look on switch/case/break.
Jan 2 '07 #6
Make sure you declare your variables first, especially if
register_globals is on. A client could potentially modify/create
variables and contents arbitrarily.

See: http://php.net/register_globals

On Jan 2, 8:12 am, william <b...@no.spamwrote:
On Tue, 02 Jan 2007 05:47:20 -0800, Jeff Vaccaro wrote:
How come this doesn't work?
What am I doing wrong?
$type = $_GET['functionType'];
if ($type == 'Add'){
$AddSQL = "INSERT INTO...";
echo $AddSQL;
}elseif ($type == 'Update'){
$UpdateSQL = "Update ...";
echo $UpdateSQL;
}elseif ($type == 'Delete'){
$DelSQL = "DELETE FROM ...";
echo $DelSQL;
}you should make your code more readable (for yourself)
have a look on switch/case/break.
Jan 3 '07 #7

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

Similar topics

5
by: Andreas Paasch | last post by:
I'm attempting to trigger things based on time. I have one shop that has opening hours, closing hours and lunch hours store as full hour values, integer, in MySQL. I retrieve them, based on...
27
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
6
by: SB | last post by:
This while loop keeps repeating even when a correct character is entered.... cout<<endl<<"What day would you like to schedule the appointment?"<<endl; cout<<endl<<"Enter 'M' for Monday, 'T' for...
2
by: Anurag | last post by:
This simple one beats me all ends up(sincerely). I have been doing DB2 UDB for some time now, reading a lot of good discussions in this forum, writing some answers, asking a lot more but this...
3
by: ChrisHadley | last post by:
My simple sortheap configuration question is: the sortheap parameter specifies the amount of memory used by agents for sorts. Is this value the total for all agents or for each? Sort heap...
5
by: Tim::.. | last post by:
Can someone tell me how I convert this simple SQL statement so I can use it in ASP.NET??? I have an issue with the quotation marks and wondered if there is a simple rule for converting the sql...
14
by: dba_222 | last post by:
Dear experts, Again, sorry to bother you again with such a seemingly dumb question, but I'm having some really mysterious results here. ie. Create procedure the_test As
7
by: Helpful person | last post by:
I am new to Javascript and have a fairly straightforward question. I am trying to use an image as a link to open a new page with the onmouseclick event. In general this seems to work fine with...
1
by: Rahul Babbar | last post by:
Hi, I ran the scripts in a file from Command Line Processor and it gave the error for all the constraints being added, but not the indexes being added. For a simple statement like Alter...
7
by: CSharper | last post by:
Yesterday I had a heated discussion with my colleagues on what is a data centric application and having business logic in sql. I have group of people who wants to include all the business logic in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...
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...

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.