Professional Web Applications Themes

Updating records in a database (php) - Dreamweaver AppDev

I am just beginning this.... I have tried to follow some tutorials but I am having no luck. I get the first record in the database... that works fine, but I can't choose another record..... tried a dynamic list menu but I cannot get it to change the records so that I can update a different one. Can anyone help?...

  1. #1

    Default Updating records in a database (php)

    I am just beginning this.... I have tried to follow some tutorials but I am
    having no luck.
    I get the first record in the database... that works fine, but I can't choose
    another record..... tried a dynamic list menu but I cannot get it to change the
    records so that I can update a different one.

    Can anyone help?

    EliDee Guest

  2. #2

    Default Re: Updating records in a database (php)

    Hi,
    You have to use two pages to accomplish this
    a) create a page index.php - that will list all the records in your table
    - create recordset with some fields to show in the list
    - create a "Dynamic Table" (from the application table)
    - add a Navigation Bar
    - create links to your detail page- inside the Repeat Region use a link
    to a detail.php?id=<?php echo $row_recordset["field"];?> page.

    b)inside the detail page, create the Recordset filtered after the id URL
    parameter

    With it, create an Update Record Wizard

    This should do it

    Alexandru

    EliDee wrote: 

    --
    InterAKT Online - Dreamweaver extensions
    http://www.interaktonline.com/
    Alexandru Guest

  3. #3

    Default Re: Updating records in a database (php)

    EliDee wrote: 

    You need to create a recordset that retrieves everything in your table:

    SELECT * FROM myTable

    Then create a table with two rows, and at least two columns. Put
    headings in the first row to identify the columns. In the second row,
    insert dynamic data from the Bindings panel for columns that will help
    identify each record. In the final column, type update. Highlight
    update, and link to the page that contains your update form, and set the
    Primary key of your record as the parameter. So you will get something
    like this in code view:

    <a href="update.php?id=<?php echo $row_recordset['id']; ?>">Update</a>

    Highlight the second row in the table, and apply a Repeat Region server
    behavior. That creates a table that will show all records, and when you
    click the Update link, it will take you to update.php, and pass the ID
    of your selected item in the URL.

    That's the basic principle. There's obviously a lot more to explain, but
    it takes several pages of my book, so it's not possible to type
    everything out here in detail all over again.

    Hopefully, that will point you in the right direction.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Guest

  4. #4

    Default Re: Updating records in a database (php)

    Guys
    thanks.... I've tried this and everything works .... except for the same old
    problem....

    I can't update - it only gives me the first record in the table regardless of
    the link...

    I'm wondering if I am doing something wrong with the recordset?

    EliDee Guest

  5. #5

    Default Re: Updating records in a database (php)

    ok, with a bit more investigation...

    the problem seems to be linked with the "ID" field as the url says basically
    I have clicked on link for id3 - however the update form still shows the record
    for id1....

    anyone got any ideas?

    this is driving me mad :(

    EliDee Guest

  6. #6

    Default Re: Updating records in a database (php)

    EliDee wrote: 

    In the Recordset dialog box for the update form, you need to set the
    Filter. The first field will contain the name of the Primary key column
    in the database table. The field alongside should be set to "=". In the
    third field, select "URL Parameter", and in the fourth field, type "id"
    (or whatever your query string contains).

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Guest

  7. #7

    Default Re: Updating records in a database (php)

    Yup this is in place....
    but now the repeating table only lets me view the first record?
    EliDee Guest

  8. #8

    Default Re: Updating records in a database (php)

    EliDee wrote: 

    On the update page you should only be able to see one record anyway. The
    id sent in the query string should identify the correct one, and the
    filter used to retrieve it.

    Have you applied the filter to the page that's meant to display all
    records instead?

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Guest

  9. #9

    Default Re: Updating records in a database (php)

    ok, struggling to explain

    made a page which shows all the records - called index.php (on this I have a
    recordset for the table in the database. Not filtered or sorted cause if I
    filter I only see one record)
    On this page I have a dynamic table which shows all records and has an update
    link at the side of each record.
    This link is update.php?<?php echo $row_Recordset1['id']; ?>=

    This links obviously to the update.php page
    I had to make a new recordset for this page, on this one I have it filtered by
    the "ID" which is also URL parameter.
    I have used the update form wizard to make a form for updating the record
    selected on the previous page.

    The location bar on the browser shows that it i s choosing the correct "id"
    and tranfering that
    http://localhost/testing/update.php?4=

    but the next page with the update form on is still showing the first
    record.....even though the url bar on the brower says another record.

    does this make sense?

    by the way I really appreciate your help!
    on this page I have an

    EliDee Guest

  10. #10

    Default Re: Updating records in a database (php)

    EliDee wrote: 

    Which update form wizard? Are you referring to the Update Record server
    behavior, or something else?

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Guest

  11. #11

    Default Re: Updating records in a database (php)

    using the tools at the top, in applications, there is an option for an update form wizard which deals with the server behaviour.
    EliDee Guest

  12. #12

    Default Re: Updating records in a database (php)

    EliDee wrote: 

    I must admit that I never knew that option existed. It strikes me as
    being pretty badly constructed, because it automatically capitalizes the
    first letter of each form field. That doesn't matter on Windows, but it
    will cause your update page to fail on a Linux system.

    Still, the answer is exactly the same as before. When creating the
    Recordset for the update page (not the page with all the records on it),
    you need to set the filter to the variable passed through the query string.

    I tested it with a table called singers, a recordset called rst_Singers,
    and a primary key called singer_id. This is the code that appears in the
    update page, just above the page's Doctype:

    $colname_rst_Singer = "1";
    if (isset($_GET['singer_id'])) {
    $colname_rst_Singer = (get_magic_quotes_gpc()) ? $_GET['singer_id'] :
    addslashes($_GET['singer_id']);
    }
    mysql_select_db($database_connMMtest, $connMMtest);
    $query_rst_Singer = sprintf("SELECT * FROM singers WHERE singer_id =
    %s", $colname_rst_Singer);
    $rst_Singer = mysql_query($query_rst_Singer, $connMMtest) or
    die(mysql_error());
    $row_rst_Singer = mysql_fetch_assoc($rst_Singer);
    $totalRows_rst_Singer = mysql_num_rows($rst_Singer);

    This is the important line:

    $query_rst_Singer = sprintf("SELECT * FROM singers WHERE singer_id =
    %s", $colname_rst_Singer);

    Notice that there is a WHERE clause in the query. If you are always
    getting the first record, it means you either don't have a WHERE clause,
    or that the details of your filter are wrong.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Guest

  13. #13

    Default Re: Updating records in a database (php)

    David Powers wrote:
     

    I've taken a closer look at it now - the capitalization is for the HTML
    display only, so it doesn't make any difference to the way it works on
    Windows/Linux.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Guest

  14. #14

    Default Re: Updating records in a database (php)

    I'm sorry to keep bugging you, but this is still causing me grief.
    This is all the code above DOCTYPE.....

    everything works, it even update sthe record, but it still will only give me
    the first record

    aaaaaaarrrrrrrrrrrrrrrrrrrrrgggggggggggggggggggggg


    function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
    $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
    "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
    $updateSQL = sprintf("UPDATE singer SET id_record=%s, name=%s, email=%s,
    `date`=%s WHERE singer_id=%s",
    GetSQLValueString($_POST['id_record'], "int"),
    GetSQLValueString($_POST['name'], "text"),
    GetSQLValueString($_POST['email'], "text"),
    GetSQLValueString($_POST['date'], "date"),
    GetSQLValueString($_POST['singer_id'], "int"));

    mysql_select_db($database_connect, $connect);
    $Result1 = mysql_query($updateSQL, $connect) or die(mysql_error());

    $updateGoTo = "index.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $updateGoTo));
    }

    $colname_rst_singer = "singer_id";
    if (isset($_GET['singer_id'])) {
    $colname_rst_singer = (get_magic_quotes_gpc()) ? $_GET['singer_id'] :
    addslashes($_GET['singer_id']);
    }
    mysql_select_db($database_connect, $connect);
    $query_rst_singer = sprintf("SELECT * FROM singer WHERE singer_id = %s",
    $colname_rst_singer);
    $rst_singer = mysql_query($query_rst_singer, $connect) or die(mysql_error());
    $row_rst_singer = mysql_fetch_assoc($rst_singer);
    $totalRows_rst_singer = mysql_num_rows($rst_singer);


    EliDee Guest

  15. #15

    Default Re: Updating records in a database (php)

    EliDee wrote: 

    I'm afraid you're not coming across very clearly. If everything works,
    and the record is being updated, that's all the Update Record Wizard is
    meant to do.

    What only gives you the first record? What is it that you actually want?

    To update records, you first display a list of all records. You then
    select one record to update. End of story. If you then want to display
    all records after updating, you have to create a new recordset to
    display them.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Guest

  16. #16

    Default Re: Updating records in a database (php)

    I have created a page that displays all records....
    from there I choose the record I want to update and that link takes me to the
    update page where I should be able to update that record.

    However it takes me to the update page which displays the first record in the
    table, no matter which link I use (and the links all tell it the correct record)

    I guess I'm just not meant to do this



    EliDee Guest

  17. #17

    Default Re: Updating records in a database (php)

    EliDee wrote: 

    As I have explained before, the Recordset in the second page must
    contain a filter to select the correct record. Say, for example that
    your primary key column is called book_id, the link from the page that
    lists all books should be something like this

    update.php?book_id=5

    In update.php, when you create the recordset, set it to select all
    columns. Then in the bottom half of the recordset dialog box, set
    Filter. The first box is a drop-down menu that should contain all the
    names of columns in your table. Select the column that represents the
    primary key (in my example, it's book_id). In the field alongside,
    select "=" from the drop-down menu. In the second row of filter fields,
    select "URL parameter", and in the final one type the name of the
    parameter after the question mark in the URL. Again, in this example, it
    will be book_id.

    That will then select the correct record from the table. If things are
    going wrong, start with a completely blank page again for update.php.
    Since you've been struggling so long, it is quite possible that you have
    more than one recordset on your page, and you're picking up the wrong
    one for display in the update form.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Guest

  18. #18

    Default Re: Updating records in a database (php)

    I GOT IT WORKING!!!!!!

    Silly mistake with the parameters!!!

    Just a question now.

    Can you make an update form which will work if you are only using one table?

    All the examples I have seen use two

    EliDee Guest

  19. #19

    Default Re: Updating records in a database (php)

    EliDee wrote: 

    Good.
     

    That's often the case.
     

    What do you mean by one table? One HTML table or one database table? If
    it's the second, the answer is yes. If it's the first, I'm not really
    sure what you're trying to achieve.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Guest

Similar Threads

  1. Updating Multi records
    By rddave51 in forum Dreamweaver AppDev
    Replies: 1
    Last Post: April 10th, 04:37 PM
  2. Updating Multiple records fields in a database atonce
    By kris f in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: February 17th, 03:36 AM
  3. Updating database records in a datagrid
    By EmJayEm in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: December 23rd, 04:52 AM
  4. Updating records when using a subform
    By M.Lubi in forum Microsoft Access
    Replies: 0
    Last Post: July 23rd, 08:44 PM
  5. Updating Multiple Records
    By Jordan Marton in forum Macromedia Dreamweaver
    Replies: 5
    Last Post: July 10th, 08:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139