Updating PHP Generated Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • onlymars
    New Member
    • Mar 2008
    • 13

    Updating PHP Generated Form

    Hi all fellows, i am in a messed up situation right now, i have a table in mysql containing different currencies and their values, i have generated a form in php which display them both, but now i want to update them. my mysql database has 2 fields 1. curr_name 2. curr_amount, i am reading both of them in a text box so that it can be updated, my php code here.. [php]echo "<table width='100%'>";
    while($curr=mys ql_fetch_array( $result2))
    {
    $a=$curr['curr_name'];

    echo "<tr><td>";

    echo "<input name='" . $curr['curr_name'] . "' value='" . strtoupper($a) . "'>";

    echo "<td><input name='" . $curr['curr_name'] . "' value='" . $curr['curr_amount'] . "'>";
    echo "<td><a href='delete.ph p?currency=" . $curr['curr_name'] . "' >Delete Record</a>";

    }
    echo "</table>";[/php]as u would have noticed i am also deleting the record by sending information by GET method, which is working, but i need to update the values in the text fields.
    this form has also function of inserting new records, so it has update, insert and delete opeartions. only update is messed up.
    Plz help me out.
    Last edited by ronverdonk; Mar 30 '08, 08:48 PM. Reason: code tags!!
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Welcome to The Scripts!

    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      You only showed some form building code for the DELETE record. What about the code for the update/insert.
      And where is the scipt that handles the insert and/or update request?

      And show that code within the appropriate code tags, as requested before.

      Ronald

      Comment

      • onlymars
        New Member
        • Mar 2008
        • 13

        #4
        Sorry man i am a newcomer to this forum thats y didn't knew the tags. i am reaind the records from mysql but am not sure how to catch them on my update page, the delete and insert new records page's are easy but i am stuck in update page cause all the textboxes will have the same name making it a aray of values, so how do i catch them on next page and update the values. Thanx

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          You want us to guess what your code looks like? Or are you looking for a freebie?
          You show (part of) a script that works ok to you but you don't want to show the other code, the one that the problem is about.

          When you seek help, but do not want to show any code for the form and the update script you have this far, we cannot help you in any way.

          Ronald

          Comment

          • dlite922
            Recognized Expert Top Contributor
            • Dec 2007
            • 1586

            #6
            Originally posted by onlymars
            Sorry man i am a newcomer to this forum thats y didn't knew the tags. i am reaind the records from mysql but am not sure how to catch them on my update page, the delete and insert new records page's are easy but i am stuck in update page cause all the textboxes will have the same name making it a aray of values, so how do i catch them on next page and update the values. Thanx
            An update is usually done by the primary key (or Unique field) of the table.

            the key (if not relevant for the user) is usually in a hidden input field.

            To make an update, your SQL would look something like this:
            [code=php]UPDATE tableName SET fieldName = " . $variable . "... WHERE primaryKeyField = " . $value; [/code]
            I don't know what your table looks like, but if you post it we can help you make an update SQL statement if you can't figure it out.

            good luck,

            DM
            Last edited by ronverdonk; Mar 31 '08, 08:41 AM. Reason: code tags!!

            Comment

            • onlymars
              New Member
              • Mar 2008
              • 13

              #7
              ok folks i am hell sorry to all u, i dont know how to get u people understand my problem, here is the code
              [code=php]
              $checked= $_POST['check'];

              $ids = (is_array($chec ked)) ? implode(',', $checked) : $checked;
              mysql_query ("UPDATE currency SET curr_amount IN($ids)");
              [/code]

              this page recieves the array of values but is unable to update the table, if u fellows dont undertand it yet again then plz dont mind i will send u both pages code in some time.
              thanx for ur patience

              Comment

              • onlymars
                New Member
                • Mar 2008
                • 13

                #8
                helloo guys i have the code now with me, sorry for being alil late, this is my entry.php code
                [code=php]
                echo "<table width='100%'>";
                while($curr=mys ql_fetch_array( $result2))
                {
                $a=$curr['curr_name'];
                $b=$curr['curr_amount'];


                echo "<tr><td class='style4' width='100'>";


                echo "<input name='name[]' class='style4' size='15' value='" . $a . "'>";
                echo "<td class='style4' width='100'>";
                echo "<input name='amount[]' class='style4' size='15' value='" . $b . "'>";

                }
                echo "</table>";
                [/code]
                and here is my update.php code,
                [code=php]
                $name= $_POST['name'];
                $amount=$_POST['amount'];


                $ids = (is_array($name )) ? implode(',', $name) : $name;
                mysql_query ("UPDATE currency SET curr_name IN($ids)");

                $ids2 = (is_array($amou nt)) ? implode(',', $amount) : $amount;
                mysql_query ("UPDATE currency SET curr_amount IN($ids2)");


                echo $ids . "<br>";
                echo $ids2;
                [/code]

                i receives all the values from text boxes as i have printed them in last lines so that i can see if it gets the array. so i recieve all the values but i guess i am not writing the update line correct, while if i write delete insteate of update then it works but something is wrong with update.

                Comment

                Working...