mayman212 Posted September 21, 2011 Share Posted September 21, 2011 <?php switch($_GET['action']){ case 'delete': break; case 'edit': case 'write': if($action=='edit'){ $form_action = 'edit_ok'; echo 'Edit Page'; }else{ $form_action = 'write_ok'; echo 'Write Page'; } ?> <?php $id=$_GET['id']; $result = mysql_query("SELECT * FROM project_data WHERE id='$id'"); $row = mysql_fetch_array($result); ?> <table border = "1"> <form action="switch.php?id=<?php echo $row['ID']?>&action=[color=purple][b]<?php echo $action ?>[/b][/color]" method="post"> <tr> <td>Date Of Birth</td> <td><input type="text" name="dateofbirth" value="<?php echo $row['Date_Of_Birth']?>"/></td> </tr> <tr> <td>Gender</td> <td><input type="radio" name="gender" value="male" <?php if($row['Gender']=='male'){echo 'checked';}?>/> Male<input type="radio" name="gender" value="female" <?php if($row['Gender']=='female'){echo 'checked';}?>/> Female</td> </tr> <tr> <td>Title</td> <td><select name="title"> <option value="">Please Select</option> <option value="Mr" <?php if($row['Title']=='Mr'){echo 'selected';}?>>Mr</option> <option value="Ms" <?php if($row['Title']=='Ms'){echo 'selected';}?>>Ms</option> <option value="Mrs" <?php if($row['Title']=='Mrs'){echo 'selected';}?>>Mrs</option> <option value="Miss" <?php if($row['Title']=='Miss'){echo 'selected';}?>>Miss</option> <option value="Other" <?php if($row['Title']=='Other'){echo 'selected';}?>>Other</option> </select></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="firstname" value="<?php echo $row['First_Name']?>"/></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lastname" value="<?php echo $row['Last_Name']?>" /></td> </tr> <tr> <td>Address Line 1</td> <td><input type="text" name="address1" value="<?php echo $row['Address_Line_1']?>" /></td> </tr> <tr> <td>Address Line 2</td> <td><input type="text" name="address2" value="<?php echo $row['Address_Line_2']?>" /></td> </tr> <tr> <td>City</td> <td><input type="text" name="postcode" value="<?php echo $row['City']?>" /></td> </tr> <tr> <td>Postcode</td> <td><input type="text" name="postcode" value="<?php echo $row['Postcode']?>" /></td> </tr> <tr> <td>Contact No</td> <td><input type="text" name="contactno" value="<?php echo $row['Contact_No']?>" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" value="<?php echo $row['Email']?>"/></td> </tr> <tr> <td>Additional Info</td> <td><textarea rows="10" cols="30" name="note"><?php echo $row['Additional_Comment']?></textarea></td> </tr> <tr> <td><input type="submit" value="Update" /></td> <td><a href='switch.php'>Main Page</a></td> </tr> </table> </form> <?php break; //case 'write'; ?> <!--<table border = "1"> <form action="switch.php?action=write_ok" method="post"> <table> <tr> <td>Date Of Birth</td> <td><input type="text" name="dateofbirth" /></td> </tr> <tr> <td>Gender</td> <td><input type="radio" name="gender" value="male" />Male<input type="radio" name="gender" value="female" /> Female</td> </tr> <tr> <td>Title</td> <td><select name="title"> <option value="" selected="selcted">Please Select</option> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Ms">Ms</option> <option value="Other">Other</option> </select></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="firstname" /></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lastname" /></td> </tr> <tr> <td>Address Line 1</td> <td><input type="text" name="address1" /></td> </tr> <tr> <td>Address Line 2</td> <td><input type="text" name="address2" /></td> </tr> <tr> <td>City</td> <td><input type="text" name="city" /></td> </tr> <tr> <td>Postcode</td> <td><input type="text" name="postcode" /></td> </tr> <tr> <td>Contact No</td> <td><input type="text" name="contactno" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Additional Info</td> <td><textarea rows="15" cols="30" name="note">Please Enter Any Additional Information</textarea></td> </tr> <tr> <td><input type="submit" value="Submit"></td> <td><a href='switch.php'>Back</a></td> </tr> </table> </form>--> <?php //break; I have this code, which is basically a form for inputting and another for editing. As you can see I have made one part a comment as I want just the edit part to control the input and edit, which is shown at the very beginning with write case, and the seperate edit case, all I need to complete it is the part that I have highlighted in purple/bold. Does anybody have any help? Quote Link to comment https://forums.phpfreaks.com/topic/247592-switch-help/ Share on other sites More sharing options...
StormTheGates Posted September 21, 2011 Share Posted September 21, 2011 What exactly is the problem? Your form is using POST, why use GET? Quote Link to comment https://forums.phpfreaks.com/topic/247592-switch-help/#findComment-1271424 Share on other sites More sharing options...
WebStyles Posted September 21, 2011 Share Posted September 21, 2011 lots of things missing or don't make sense here I only read about 15 lines of your code and I have these questions: ... where's your question? why are you using that redundant if inside the switch statement? where does $action come from? where and how do you connect to mysql? why is your query based on a url variable that you don't check for existence first? why is the field id in lowercase when you create your query, but in uppercase when you try to retrieve it? why are you using <form action="switch.php?id=<?php echo $row['ID']?> if you already had the same id from $_GET['id'] even before your query? ... anyway, since the title was 'switch help', here's how a switch statement works: switch($_GET['action']){ case 'delete': // code to delete stuff break; case 'edit': // code to edit stuff break; case 'write': // code to write stuff break; } Quote Link to comment https://forums.phpfreaks.com/topic/247592-switch-help/#findComment-1271576 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.