Jump to content

edit and delete


bschultz

Recommended Posts

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

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

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

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.