bschultz Posted April 11, 2008 Share Posted April 11, 2008 I'm trying to write a form script to edit or delete certain records in the DB. Here's what I have: <?php require "config.php"; $conn1 = $connect; @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $date = $_POST[date]; $type = $_POST[type]; $event = $_POST[event]; $action = $_POST[action]; $comments = $_POST[comments]; $row_number = $_POST[row_number]; $cmd = $_POST[cmd]; for ($i=0;$i<count($_POST[event]);$i++){ if($cmd[$i] =="delete") { $sqldelete = "DELETE FROM cancellations WHERE row_number='$_POST[row_number]'"; $resultdelete = mysql_query($sqldelete) or die ("Error in Delete Query" . mysql_error()); echo "<meta http-equiv=Refresh content=1;url='/weather/edit.php'>" ; } else $usql = "UPDATE cancellations SET date='$date[$i]', type='$type[$i]', event='$event[$i]', action='$action[$i]', comments='$comments[$i]' WHERE row_number='$row_number[$i]'"; // above compiles query $dosql = mysql_query($usql); // executes query } if ($dosql){ echo "<p>Thank You, your entry has been submitted!</p> <meta http-equiv=Refresh content=1;url='/weather/edit.php'>"; } else{ echo mysql_errno().": ".mysql_error()."<BR>"; } mysql_close (); ?> It's not editing or deleting the record, and I'm not getting an error. Any idea what I'm doing wrong? Link to comment Share on other sites More sharing options...
fenway Posted April 11, 2008 Share Posted April 11, 2008 Echo $sqldelete. Link to comment Share on other sites More sharing options...
bschultz Posted April 11, 2008 Author Share Posted April 11, 2008 DELETE FROM cancellations WHERE row_number='Array' That obviously isn't right! Link to comment Share on other sites More sharing options...
fenway Posted April 11, 2008 Share Posted April 11, 2008 Try "DELETE FROM cancellations WHERE row_number='".$_POST[row_number]."'" Link to comment Share on other sites More sharing options...
bschultz Posted April 11, 2008 Author Share Posted April 11, 2008 I tried "DELETE FROM cancellations WHERE row_number='$row_number[$i]'"; and it seemed to work (I"m still testing)...what would the difference between the two statements be? Link to comment Share on other sites More sharing options...
bschultz Posted April 11, 2008 Author Share Posted April 11, 2008 neither one worked to delete...but I can now edit. Link to comment Share on other sites More sharing options...
fenway Posted April 11, 2008 Share Posted April 11, 2008 I tried "DELETE FROM cancellations WHERE row_number='$row_number[$i]'"; and it seemed to work (I"m still testing)...what would the difference between the two statements be? Depends if those two values are different. Link to comment Share on other sites More sharing options...
bschultz Posted April 13, 2008 Author Share Posted April 13, 2008 I found out that I've got the wrong row number when deleting....even with this code "DELETE FROM cancellations WHERE row_number='".$_POST[row_number]."'" Also, with that code, I can't edit...with this code "DELETE FROM cancellations WHERE row_number='$row_number[$i]'"; however, I can edit, but it deletes the wrong record. Link to comment Share on other sites More sharing options...
fenway Posted April 14, 2008 Share Posted April 14, 2008 Well, that's a PHP issue... you're passing the wrong UID. Link to comment Share on other sites More sharing options...
bschultz Posted April 14, 2008 Author Share Posted April 14, 2008 you're right...as always! Thanks for the help. I'll repost in the php thread. Link to comment Share on other sites More sharing options...
Recommended Posts