dennismonsewicz Posted August 21, 2007 Share Posted August 21, 2007 <?php include "../includes/header.php"; $action = $_GET['action']; $rowid = $_GET['id']; switch($action) { /* MORE DETAILED VIEW */ case "view": include "../includes/db_login.php"; $query = "SELECT * FROM tblname WHERE rowid = '$rowid'"; $result = mysql_query( $query ); if(!$result) { die("Could not query the database: <br/>" . mysql_error()); } while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $rowid = $row['rowid']; $company = $row['company']; $product = $row['product']; $description = $row['description']; $web = $row['web']; $last = $row['last']; $used = $row['used']; $active = $row['active']; echo ' <p class="casetext">Below is a more detailed description of <b>' . $product . '</b>.</p> <table border="0" align="center" cellpadding="4" style="margin-bottom: 5px;"> <tr> <td>Company:</td> <td>' . $company . '</td> </tr> <tr> <td>Product:</td> <td>' . $product . '</td> </tr> <tr> <td>Description:</td> <td>' . $description . '</td> </tr> <tr> <td>Web Address:</td> <td><a href="' . $web . '" target= "_blank">' . $web . '</a></td> </tr> <tr> <td>Last Used:</td> <td>' . $last . '</td> </tr> <tr> <td>When was <b>' . $product . '</b> last used:</td> <td>' . $used . '</td> </tr> <tr> <td>Is <b>' . $product . '</b> Active or Inactive?:</td> <td>' . $active . '</td> </tr> </table> <p class="casetext" style="font-size: 125%;"><a href="hrdb.php">Go back to database?</a></p> '; } mysql_close($connection); include_once "../includes/footer.php"; exit; break; /* END DETAILED VIEW */ /* EDIT MODE */ case "edit": include "../includes/db_login.php"; $query = "SELECT * FROM tblname WHERE rowid = '$rowid'"; $result = mysql_query( $query ); if(!$result) { die("Could not query the database: <br/>" . mysql_error()); } while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id = $row['rowid']; $company = $row['company']; $product = $row['product']; $description = $row['description']; $web = $row['web']; $last = $row['last']; $used = $row['used']; $active = $row['active']; echo ' <p class="casetext">Below is a more detailed description of <b>' . $product . '</b>.</p> <form action="hrdbcase.php?action=doedit" method="post" name="form1"> <p><input type="hidden" name="rowid" value="' . $id . '" /></p> <table border="0" align="center" cellpadding="4" style="margin-bottom: 5px;"> <tr> <td>Company:</td> <td><input type="text" name="company" value="' . $company . '" /></td> </tr> <tr> <td>Product:</td> <td><input type="text" name="product" value="' . $product . '" /></td> </tr> <tr> <td>Description:</td> <td><input type="text" name="description" value="' . $description . '" /></td> </tr> <tr> <td>Web Address:</td> <td><input type="text" name="web" value="' . $web . '" /></td> </tr> <tr> <td>Last Used:</td> <td><input type="text" name="last" value="' . $last . '" /></td> </tr> <tr> <td>When was <b>' . $product . '</b> last used:</td> <td><input type="text" name="used" value="' . $used . '" /></td> </tr> <tr> <td>Is <b>' . $product . '</b> Active or Inactive?:</td> <td><input type="text" name="active" value="' . $active . '" /></td> </tr> <tr> <td></td> <td><input type="submit" value="Submit" /></td> </tr> </table> </form> <p class="casetext" style="font-size: 125%;"><a href="hrdb.php">Go back to database?</a></p> '; } mysql_close($connection); include "../includes/footer.php"; exit; break; /* END EDIT MODE*/ /* EDIT ACTION HELD HERE */ case "doedit": include "../includes/db_login.php"; $query=" UPDATE tblname SET company = '" . $company . "', product = '" . $product . "', description = '" . $description . "', web = '" . $web . "', last = '" . $last . "', used = '" . $used . "', active = '" . $active . "' WHERE rowid = '" . $rowid . "' "; $result = mysql_query($query); if(!$result) { die("Could not query the database: <br/>" . mysql_error()); } else { echo '<p class="casetext">Item Updated</p>'; } mysql_close($connection); include "../includes/footer.php"; exit; break; /* END EDIT ACTION */ case "delete": $id = $_GET['id']; echo '<p class="casetext">Are you sure you want to <strong>delete</strong> this item?<br/>'; echo 'This is a final action. If you make a mistake, this cannot be undone.<br/>'; echo '<a href="hrdbcase.php?action=dodelete&id=' . $id . '"><big>Yes, Delete This</big></a> | <a href="hrdb.php"><big>No, Go Back</big></a> '; echo '</p>'; include_once "../includes/footer.php"; exit; break; case "dodelete": include "../includes/db_login.php"; $query="DELETE FROM hrlanding WHERE rowid='" . $id . "'"; $result = mysql_query($query); if(!$result) { die("Could not query the database: <br/>" . mysql_error()); } else { echo '<p class="casetext">Item has been permanetly deleted<br/>'; echo 'To return to the database, <a href="hrdb.php">Click Here</a></p>'; } include_once "../includes/footer.php"; exit; break; } include "../includes/footer.php"; ?> The following code above is being used to edit/updated/delete an item in a database. Well I can view the information perfectly, but when I try to edit the information, I get a successful message but the edits do not go through. And when you try to delete an item the delete command does not delete the item. I need help URGENTLY! Thanks for any suggestions in advance. -Dennis Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 If you are not getting any errors from the SQL statements, then it is most likely your WHERE clauses. For editing, you are checking the $rowid, print out $rowid right before your sql and see if it does, in fact, contain a value that is in your table. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 21, 2007 Author Share Posted August 21, 2007 Yes it is printing out the rowid. Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 Is rowid numerical? If so, you don't need the single quotes around its test value. rowid = '" . $rowid . "' should be: rowid = " . $rowid . " If it is a number. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 21, 2007 Author Share Posted August 21, 2007 I did what you suggested and got the following error: Could not query the database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 11 This occurred when trying to edit. Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 Try swapping out $rowid with a number that is known to be in the table. I am pretty sure that you shouldn't have any type of quotes when using a number so it would seem to me that $rowid might contain some kind of characters other than numerical. Just test it like this and see if it works for that row: rowid = 1 Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 21, 2007 Author Share Posted August 21, 2007 Ok... That didn't work. When I replaced it with a 1, the edit field values disappeared and nothing was being pulled out of the database. Quote Link to comment Share on other sites More sharing options...
samoht Posted August 21, 2007 Share Posted August 21, 2007 you mentioned a problem with delete it may be because you are deleting from a different table?? Don't you want to delete from tblname?? <?php $query="DELETE FROM hrlanding Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 I am pretty sure the problem is that those variables (including $rowid) simply contain nothing. They are all being set in a different case, which means, if the case is edit, the case that sets them is never being executed. You need to either set them in each case, or pass them through using GET or POST so that eahc case can pull the values. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 21, 2007 Author Share Posted August 21, 2007 ok... I got the delete command working, but I am still having problems trying to get the edit commands working properly Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 Did you fix the variables? Echo out the variables inside the "doedit" case and see if they are the right values. I don't think you are giving them values at all (unless it is in the db_login.php file.) Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted August 21, 2007 Author Share Posted August 21, 2007 ok... Yes the values are displaying. 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.