This topic is locked

Add delete button to edit page ver PHPR 3.1?

1/30/2008 8:48:24 PM
PHPRunner General questions
K
ke5rs author

Hello, I think I create these pages using 3.1

On my edit page next to the "SAVE" button I would like to have a button to delete the displayed record. I have added the following function to the jsfunctions.js page and the alert displays the record ID and then jumps have to the list page.
------------------------------------------------------------------------------------------------------------------

function deleteRecord(key){

alert(key + " Record Deleted");

document.location.href = "http://www.website.com"/page_list.php;

}

------------------------------------------------------------------------------------------------------------------
Here is the code I added to my page_edit.html template page and this part works good asking are you sure and carries the $show_key1 variable to the function above works and looks good.
-------------------------------------------------------------------------------------------------------------------------------------

<input type=button value="Delete Record" onClick="if (confirm('Delete {$show_key1}?')) deleteRecord('{$show_key1}'); return false;">

--------------------------------------------------------------------------------------------------------------------------------------
So now I have this part looking good on my page, is there something I can add to the JS function to actually delete the record.

I think I uploaded this site using the previous 3.1.

Thank you.
John

J
Jane 1/31/2008

John,
you can do the following:

  1. edit your code in the ..._edit.htm file.

    Here is a sample:
    <input type=button value="Delete Record" onClick="if (confirm('Delete {$show_key1}?')) window.location='..._edit.php?editid1={$show_key1}&delete={$show_key1}';">


2. add code to the EditOnLoad event on the Events tab.

Here is a sample:

function EditOnLoad()

{

global $conn;

if ($_REQUEST["delete"])

{

$str = "delete from TableName where RecordID=".$_REQUEST["delete"];

db_exec($str,$conn);

?><script>

window.location='tablename_list.php';

</script><?php

}

}

K
ke5rs author 2/11/2008

Thanks Jane,

I still have a problem...

Within my tablename_events.php, I added this code
//=====================================================

function EditOnLoad()

{

global $conn;
if ($_REQUEST["delete"]){

$str = "DELETE FROM table1 WHERE call ='".$_REQUEST["delete"]."'";

echo '$str = '.$str."
".'$conn = '.$conn;

db_exec($str,$conn);

?><script>

window.location='table1 _list.php';

</script>

<?php

}

}

//====================================================
echo returns the following
$str = DELETE FROM table1 WHERE call ='TEST'

$conn = Resource id #8
$str looks good to me but $conn is returning "Resource id #8". I don't know what that is.
I have a single table "table1"

In that table is the only key field or column "call" with a record "TEST" in that field. THere are about 6 other fields that are not keys.
The record is not getting deleted and I am getting this php error.

Error type 256

Error description 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 'call ='TEST'' at line 1

URL ....com/table1_edit.php?editid1=TEST&delete=TEST
Thank you for any help.
John

John,

you can do the following:

  1. edit your code in the ..._edit.htm file.

    Here is a sample:
  2. add code to the EditOnLoad event on the Events tab.

    Here is a sample:

Alexey admin 2/12/2008

John,
possibly "call" is a MySQL reserved word and can not be used as a field name in SQL queries.

Try to enclose it in field wrappers:

$str = "DELETE FROM worldsstv WHERE `call` ='".$_REQUEST["delete"]."'";

K
ke5rs author 2/12/2008

THank you Alexey,

That fix it. Very cool. Thank you very much...

I will try now to remember to check for MySQL reserved words when designing a database...

Again thank you <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=25779&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
John

John,

possibly "call" is a MySQL reserved word and can not be used as a field name in SQL queries.

Try to enclose it in field wrappers: