Has anyone else come across this. When i delete a line in mysql with:
delete from workorders where workorder_id=$id
it removes the whole line. Workorder_id and everything; However, in php when i use that query it leaves the workorder_id leaving a blank line. Any ideas as to why i get different results?
From
Pizmal
php/mysql delete problem
Moderator: General Moderators
Here is an example. Will post my code when I can (at work). Sorry if its a little choppy just threw it together.
// if someone pushed submit on form either update line or create
if ($submit) {
if ($id) {
$sql = update.....
} ELSE {
$sql = insert.....
}
$result =mysql_query($sql);
echo "your record has been updated or created;
// If they push the delete button remove line
} ELSEIF ($delete) {
$sql = "DELETE FROM workorders WHERE workorder_id="$id";
$result = mysql_query($sql);
} ELSE {
// show section coming from search page....
// if someone pushed submit on form either update line or create
if ($submit) {
if ($id) {
$sql = update.....
} ELSE {
$sql = insert.....
}
$result =mysql_query($sql);
echo "your record has been updated or created;
// If they push the delete button remove line
} ELSEIF ($delete) {
$sql = "DELETE FROM workorders WHERE workorder_id="$id";
$result = mysql_query($sql);
} ELSE {
// show section coming from search page....
if($id){
//update
} else {
//insert
} elseif {
//delete
}
So looks to me like it will do an insert then a delete, which would explain what you are seeing.
You probably want something more along the lines of:
//update
} else {
//insert
} elseif {
//delete
}
So looks to me like it will do an insert then a delete, which would explain what you are seeing.
You probably want something more along the lines of:
Code: Select all
if(!empty($_POST['delete'])){
//delete here
} else {
if(empty($_POST['id'])){
//insert
} else {
//update
}
}