careym1989 Posted December 23, 2008 Share Posted December 23, 2008 Hello again! Got another question. I'm using switch and cases to change the command. Examples of the commands are: view, add, edit, delete. Everything else is working perfectly, but I'm having trouble with the 'edit' case. Here's the code: case 'edit': $submitted == $_REQUEST['submitted']; if($submitted=="1") { $text == $_REQUEST['text']; $url == $_REQUEST['url']; $id == $_REQUEST['id']; include("MySQL_Connect.php"); $sql = "UPDATE navbar SET text='$text', url='$url' WHERE id='$id'"; $result = mysql_query($sql); if($result) { echo mysql_affected_rows(); echo " records successfully updated."; exit; } else { echo "Error encountered. Try again."; } } else { echo "Please fill out the form above and click \"Submit.\""; } ?> </p> <p> <?php $id = $_REQUEST['id']; include("MySQL_Connect.php"); $sql = "SELECT * FROM navbar WHERE id='$id'"; $result = mysql_query($sql); while($info = mysql_fetch_assoc($result)) { ?> <form name="nb" method="post" action="http://www.blackandwhitecms.com/Control_Panel/Navigation_Bar.php?cmd=edit&id=<?php echo $id ?>"> <table width="476" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="112">Link Title</td> <td width="364"><label> <input name="text" type="text" id="text" size="40" value="<?php echo $info[text] ?>" /> </label></td> </tr> <tr> <td>Link URL</td> <td><label> <input name="url" type="text" id="url" size="40" value="<?php echo $info[url] ?>" /> </label></td> </tr> </table> <p> <input type="hidden" name="submitted" id="submitted" value="1" /> <input type="hidden" name="id" id="id" value="<?php echo $info[id] ?>" /> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> </p> </form> <?php } break; The problem is the $submitted if statement isn't working properly. Currently, I change the information that's in the fields and hit "Submit" and the fields change back to what they are currently in the table. Help would be much appreciated! I've tried a couple of different approaches, but none have worked. Thanks, C Quote Link to comment Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 Try some debugging (should be removed once working). $result = mysql_query($sql) or die(mysql_error() . "<br />$sql<br />"); Quote Link to comment Share on other sites More sharing options...
careym1989 Posted December 23, 2008 Author Share Posted December 23, 2008 Thanks for the speedy reply. Here's my code: $submitted == $_REQUEST['submitted']; if($submitted=="1") { $text == $_REQUEST['text']; $url == $_REQUEST['url']; $id == $_REQUEST['id']; include("MySQL_Connect.php"); $sql = "UPDATE navbar SET text='$text', url='$url' WHERE id='$id'"; $result = mysql_query($sql) or die(mysql_error($sql)); Unfortunately, it's not even debugging. I put your code first and then tried the above code. Still, nothing is appearing. Quote Link to comment Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 Can we see your form? Quote Link to comment Share on other sites More sharing options...
careym1989 Posted December 23, 2008 Author Share Posted December 23, 2008 Here's the entire page: <? session_start(); if(!session_is_registered(myusername)){ header("location:Default.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Control Panel</title> <link href="media/Style.css" type="text/css" rel="stylesheet" /> </head> <body> <img src="media/Logo.jpg" width="290" height="99" alt="BWCMS" class="topleft" /> <img src="media/ControlPanel.png" class="topmid" /> <div class="navcontainer"> <ul id="navlist"> <li><a href="Main.php">Home</a></li> <li><a href="Statistics.php">Statistics</a></li> <li><a href="Navigation_Bar.php">Navigation Bar</a></li> <li><a href="Clients.php">Clients</a></li> <li><a href="Products.php">Products</a></li> <li><a href="Updates.php">Updates</a></li> <li><a href="Help.php">Help</a></li> <li><a href="Logout.php">Logout</a></li> </ul> </div> <div class="content"> <?php if (isset($_GET['cmd'])) { switch ($_GET['cmd']) { // ADD FUNCTION case 'add': $text = $_POST['text']; $url = $_POST['url']; $submitted = $_POST['submitted']; if ($submitted == 1) { mysql_connect("mysql.blackandwhitecms.com", "bwcms", "deafly12") or die(mysql_error()); mysql_select_db("bwcms_db") or die(mysql_error()); $sql = "INSERT INTO navbar (text, url) VALUES ('$text', '$url')"; mysql_query($sql); echo "<font color=green>"; echo mysql_affected_rows(); echo " record(s) successfully added to the database."; echo "</font>"; } else { ?> <form id="navbaradd" name="navbaradd" method="post" action="http://www.blackandwhitecms.com/Control_Panel/Navigation_Bar.php?cmd=add"> <table width="476" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="112">Link Title</td> <td width="364"><label> <input name="text" type="text" id="text" size="40" value="<?php echo $text ?>" /> </label></td> </tr> <tr> <td>Link URL</td> <td><label> <input name="url" type="text" id="url" size="40" value="<?php echo $url ?>" /> </label></td> </tr> </table> <p> <input type="hidden" name="submitted" value="1" /> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> </p> </form> <?php } ?> <?php break; // DELETE FUNCTION case 'del': $id = $_GET['id']; include("MySQL_Connect.php"); $sql = "DELETE FROM navbar WHERE id='$id'"; $result = mysql_query($sql); if($result) { echo mysql_affected_rows(); echo " record successfully deleted from the database."; } else { echo "Error occurred. Please try again."; } break; // EDIT FUNCTION case 'edit': $submitted == $_REQUEST['submitted']; if($submitted=="1") { $text == $_REQUEST['text']; $url == $_REQUEST['url']; $id == $_REQUEST['id']; include("MySQL_Connect.php"); $sql = "UPDATE navbar SET text='$text', url='$url' WHERE id='$id'"; $result = mysql_query($sql) or die(mysql_error() . "<br />$sql<br />"); $resultold = mysql_query($sql2) or die(mysql_error($sql)); if($result) { echo mysql_affected_rows(); echo " records successfully updated."; exit; } else { echo "Error encountered. Try again."; } } else { echo "Please fill out the form below and click \"Submit.\""; } ?> </p> <p> <?php $id = $_REQUEST['id']; include("MySQL_Connect.php"); $sql = "SELECT * FROM navbar WHERE id='$id'"; $result = mysql_query($sql); while($info = mysql_fetch_assoc($result)) { ?> <form name="nb" method="post" action="http://www.blackandwhitecms.com/Control_Panel/Navigation_Bar.php?cmd=edit&id=<?php echo $id ?>"> <table width="476" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="112">Link Title</td> <td width="364"><label> <input name="text" type="text" id="text" size="40" value="<?php echo $info[text] ?>" /> </label></td> </tr> <tr> <td>Link URL</td> <td><label> <input name="url" type="text" id="url" size="40" value="<?php echo $info[url] ?>" /> </label></td> </tr> </table> <p> <input type="hidden" name="submitted" id="submitted" value="1" /> <input type="hidden" name="id" id="id" value="<?php echo $info[id] ?>" /> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> </p> </form> <?php } break; case 'view': $id = $_GET['id']; include("MySQL_Connect.php"); $sql = "SELECT * FROM navbar WHERE id='$id'"; $result = mysql_query($sql); while($info = mysql_fetch_assoc($result)) { echo "Text: $info[text]"; echo "<br />"; echo "URL: $info[url]"; } break; default: echo "A command is needed in the URL to continue. Please try again."; break; } } else { echo "<a href=http://www.blackandwhitecms.com/Control_Panel/Navigation_Bar.php?cmd=add>Add Record</a><br /><br /><br />"; include("MySQL_Connect.php"); $sql = "SELECT * FROM navbar ORDER BY id ASC"; $result = mysql_query($sql); while($info = mysql_fetch_assoc($result)) { echo "$info[text] links to $info[url] "; echo "<a href=http://www.blackandwhitecms.com/Control_Panel/Navigation_Bar.php?cmd=view&id=$info[id]>View</a> | <a href=http://www.blackandwhitecms.com/Control_Panel/Navigation_Bar.php?cmd=edit&id=$info[id]>Edit</a> | <a href=http://www.blackandwhitecms.com/Control_Panel/Navigation_Bar.php?cmd=del&id=$info[id]>Delete</a><br /><br />"; } } ?> </div> </body> </html> The case I'm having trouble with is case 'edit.' Delete, add, view are no problem. Quote Link to comment Share on other sites More sharing options...
careym1989 Posted December 23, 2008 Author Share Posted December 23, 2008 Quick bump. Thanks! Quote Link to comment Share on other sites More sharing options...
Mikedean Posted December 23, 2008 Share Posted December 23, 2008 Is there any reason why on the 'edit' case you are using '$_REQUEST'? Try changing it to the way adding handles it. $submitted = $_POST['submitted']; if ($submitted == 1) { Quote Link to comment Share on other sites More sharing options...
careym1989 Posted December 24, 2008 Author Share Posted December 24, 2008 Got it working. Seems the $_POST did it. Not sure why -- I've use $_REQUEST for almost everything, except for $_GET's. It seems to work as $_POST too. Thanks for the help, though! Took me a day to get that working! Marking As Solved Quote Link to comment 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.