This topic is locked

Any Sugguestions?

12/2/2006 2:51:37 PM
PHPRunner General questions
L
lawfour author

I created a DVD database for family and friends and I was wondering if anyone has a suggestion on how to include a borrow me feature that will email a user that someone would like to borrow a movie and list the movies.
Just writing it down sounds like a huge task if it is never mind.
If it is too much to do could you post that it is just too much involved so i wont keep checking for an answer.
Could be a button or check box.
Thanks

J
Jane 12/5/2006

Larry,
you can do the following:

  1. proceed to the "Visual Editor" tab
  2. turn on "HTML mode", find this line:

    <!-- delete form -->

    and add following code just before:

    <A onclick="if (!confirm('Do you really want to update these records?')) return false; frmAdmin.a.value='update'; frmAdmin.submit(); return false;"

    href="TableName_list.htm#">send email</A>
  3. proceed to the Events tab and add BeforeDelete event.

    Here is a sample code:
    function BeforeDelete($where)

    {

    //delete records

    if(@$_POST["a"]=="delete")

    return true;
    //send email with selected records

    global $conn,$strTableName;

    $email="test@test.com";

    $message="";

    $subject="Borrow";

    $rs = db_query("select * from " . $strTableName ." where ". $where,$conn);
    if($data=db_fetch_array($rs))

    {

    foreach($data as $field=>$value)

    $message.= $field." : ".$value."\r\n";

    mail($email, $subject, $message);

    }

    return false;

    }

L
lawfour author 12/8/2006

Thanks I just got back online, my cable modem broke. I tried the code and even altered it a little and it says Undefined variable: values
Error type 8

Error description Undefined variable: values

URL www.lawfour.com/dvdmovies/dvd_movies_list.php?

Error file lawfour.com/dvdmovies/include/dvd_movies_events.php

Error line 42

SQL query delete from `dvd_movies` where `dvd_movies`.`id_dvd`=138
Any help, on where to look?
Here is the code I used.
function BeforeDelete($where)

{

//delete records

if(@$_POST["a"]=="delete")

return true;
//send email with selected records
global $conn,$strTableName;
$email=$values["email_address"];

$message="";

$subject="Borrow Movie";

$headers = "From: lawfour@comcast.net" . "\r\n" ."CC: larry@lawfour.com";
$rs = db_query("select * from " . $strTableName ." where ". $where,$conn);
if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

$message.= $field." : ".$value."\r\n\n";

mail($email, $subject, $message, $headers);

}

return false;

}
Also, an added question, I noticed when I signed into the DB using this script the delete check box that is used as the borrow me link is only showed to users that the records belong to, does this mean I will have to change the security from user can view other user data but can only edit his own. I would like to keep it that way if possible.
Thanks again

Larry

J
Jane 12/8/2006

Larry,
please see my answers below:

  1. there is no $values variable in the BeforeDelete event.

    Change your code in the following way:
    global $conn,$strTableName;

    $message="";

    $subject="Borrow Movie";

    $headers = "From: lawfour@comcast.net" . "\r\n" ."CC: larry@lawfour.com";
    $rs = db_query("select * from " . $strTableName ." where ". $where,$conn);
    if($data=db_fetch_array($rs))

    {

    $email=$data["email_address"];

    foreach($data as $field=>$value)

    $message.= $field." : ".$value."\r\n\n";

    mail($email, $subject, $message, $headers);

    }

    return false;


2. I recommend you to create custom View for this table on the Datasource tables tab and then set up different permissions for this table and View.

For example, user can view or send email on the View and edit/delete records on the table.
Another way to accomplish this task is to edit generated files manually. You should be familiar with PHP for that.

Here is link to the PHP manual:

http://www.php.net/manual/en/
Also you can edit generated files manually to accomplish this task. You should be familiar with PHP for that