473,320 Members | 1,863 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,320 software developers and data experts.

switch case not working

122 100+
My form looks like this:

Expand|Select|Wrap|Line Numbers
  1.       <form action="handle_event.php" method="POST" enctype="multipart/form-data">
  2.         <table id="event_edit" border="0">
  3.           <tr>
  4.             <td>
  5.               <label for="title">TITLE: </label>
  6.             </td>
  7.             <td class="input">
  8.               <input id="title" name="title" type="text" size="80" value="<?php if (!empty($title)) {echo $title;} ?>"  />
  9.             </td>
  10.           </tr>
  11.           <tr>
  12.             <td>
  13.               <label for="description">DESCRIPTION: </label>
  14.             </td>
  15.             <td class="input">
  16.               <textarea id="description" name="description" cols="60" rows="10"><?php if ($id) {echo $description;} ?></textarea>
  17.             </td>
  18.           </tr>
  19.           <tr>
  20.             <td><label for="userfile">IMAGE: </label><?php if (!empty($filename)) echo $filename ?></td>
  21.             <td class="input"><input type="file" name="userfile" class="picture" size="67"></td>
  22.           </tr>
  23.           <tr><td>&nbsp;</td></tr>
  24.           <tr>
  25.             <td colspan="2">
  26.               <div id="admin_buttons">
  27.                 <input type="hidden" name="id" value="<?php if (isset($_GET['id'])) echo $_GET['id']; ?>" />
  28.                 <input type="hidden" name="submitted" value="TRUE" />
  29.                 <input type="image" name="delete" value="delete" src="../images/delete_button.gif" class="admin_button"  onclick="return confirm('Are you sure you want to delete this event?');" />
  30.                 <input type="image" name="update" value="update" src="../images/update_button.gif" class="admin_button" />
  31.                 <input type="image" name="add" value="add" src="../images/add_button.gif" class="admin_button" />
  32.                 <a href="event.php">
  33.                   <input type="image" name="clear" value="clear" src="../images/clear_button.gif" class="admin_button" />
  34.                 </a>
  35.               </div>
  36.             </td>
  37.           </tr>
  38.         </table>
  39.       </form>
handle_event.php looks like this:

Expand|Select|Wrap|Line Numbers
  1. $add_x = $_POST['add_x'];
  2. $add_y = $_POST['add_y'];
  3. $update_x = $_POST['update_x'];
  4. $update_y = $_POST['update_y'];
  5. $delete_x = $_POST['delete_x'];
  6. $delete_y = $_POST['delete_y'];
  7.  
  8. if (!empty($add_x) || !empty($add_y)) {
  9.     $action = add;
  10. } else if (!empty($update_x) || !empty($update_y)) {
  11.     $action = update;
  12. } else if (!empty($delete_x) || !empty($delete_y)) {
  13.     $action = delete;
  14. }
  15.  
  16. $id = $_POST['id'];
  17. $title = $_POST['title'];
  18. $description = $_POST['description'];
  19.  
  20. if (!empty($_FILES['userfile'])) {
  21.     $filename = $_FILES['userfile']['name'];
  22.     $tmpname = $_FILES['userfile']['tmp_name'];
  23.     $filesize = $_FILES['userfile']['size'];
  24.     $filetype = $_FILES['userfile']['type'];
  25.     $error = $_FILES['userfile']['error'];
  26.  
  27.     $fp      = fopen($tmpname, 'r+');
  28.     $content = fread($fp, fileSize($tmpname));
  29.     $content = addslashes($content);
  30.     fclose($fp);
  31.     if(!get_magic_quotes_gpc()) {
  32.         $filename = addslashes($filename);
  33.     }
  34. }
  35.  
  36. switch ($action) {
  37.   case "add":
  38.     $msgHead = "Add an Event";
  39.     /* do a bunch of stuff */
  40.     break;
  41.   case "update":
  42.     $msgHead = "Update an Event";
  43.     /* do a bunch of stuff */
  44.     break;
  45.   case "delete":
  46.     $msgHead = "Delete an Event";
  47.     /* do a bunch of stuff */
  48.     break;
  49. default:
  50.     echo 'Page accessed in error.';
  51.     break;
  52. }
When I click the update image, the switch should execute the statements in the update case. I've echoed the value of $action (it said $action was update) and strlen($action) just to make sure I wasn't getting something extra besides just the string "update" (I wasn't, the length was 6 as expected), but the entire switch case is being ignored and I'm getting "Page accessed in error" every time. Can anyone see what's wrong with my code?
Sep 21 '09 #1
2 3150
Dormilich
8,658 Expert Mod 8TB
well, the posted switch code works as expected. but you you should put your strings in quotation marks! (lines 9, 11, 13) unless you have these constants defined.

to check a variable better use var_dump()
Sep 21 '09 #2
Annalyzer
122 100+
Problem solved. It was actually a break missing in the part of the code I didn't give you causing lines to be interpreted that weren't relevant to the case.

Thanks for your help.
Sep 23 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
11
by: hasadh | last post by:
Hi, is the assemly code for if..else and switch statements similar. I would like to know if switch also uses value comparison for each case internally or does it jump to the case directly at...
19
by: rdavis7408 | last post by:
Hello, I have four textboxes that the user enters the price per gallon paid at the pump, the mileage per gallon and I would like to then calculate the cost per gallon and use a switch statement to...
13
by: Fei Liu | last post by:
Hi Group, I've got a problem I couldn't find a good solution. I am working with scientific data files in netCDF format. One of the properties of netCDF data is that the actual type of data is only...
22
by: Technoid | last post by:
Is it possible to have a conditional if structure nested inside a conditional switch structure? switch(freq) { case 1: CASENAME if (variable==1) { do some code }
9
by: PhreakRox | last post by:
The ToClose switch in this program is not working as expected, it allways returns a null value, if anyone knows a way to fix up the code, or can suggest a better method of doing so, your help would...
9
by: mantrid | last post by:
hello In the function below radtext is an array of 3 radio buttons with values set to 1, 2 and 3. but variables starty and finishy are not returned. ...
14
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; int main() { int i;
2
by: ALi Shaikh | last post by:
Hey switch statements are not working it gives me errors saying "case" illegal use of word. heres the code //Chinese calender Project #include <iostream.h> int main() { int year; int myear;...
7
by: Rohit | last post by:
Hi, I am working on a switch module which after reading voltage through a port pin and caterogizing it into three ranges(open,low or high), passes this range to a function switch_status() with...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.