SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Storing Document Object Model in database

    Quote Originally Posted by superdezign
    Quote Originally Posted by kkonline
    I have made the following structure which uses Dynamic Object Module (DOM) to add/remove a field on the page which works perfectly fine.
    Anyway, your question is too long and confusing. Summarize it a bit more.
    Please refer to story php code

    In simple words

    I want to send the data of all the tags fields AS ARRAY(as many fields the user creates by pressing the add tag) to database
    In storyinsert.php i have used implode function to do this.

    However my problem is what should i write in story.php to send ALL TAGS ARRAY to storyinsert.php which implodes the data and sends to db?

    If it was static i could use something like

    Code:
    tag1<input type="text" name="tag[0]" />
    tag2<input type="text" name="tag[1]" />
    tag3<input type="text" name="tag[2]" />
    Now how to do something as above in this case where the fields change with the clicks on add/remove tag link.

    --------contents of story.php------------
    Code:
    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("mysql", $con);
    mysql_close($con);
    ?>
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Add/Remove child: Javascript</title>
    <script type="text/javascript">
    <!--
    
    function insertRowPHP()
    {
    var tbl = document.getElementById('tblInsertRowPHP');
    var iteration = tbl.tBodies[0].rows.length+1;
    newRow = tbl.tBodies[0].insertRow(-1);
    var newCell = newRow.insertCell(0);
    newCell.innerHTML = 'tag ' + iteration;
    var newCell1 = newRow.insertCell(1);
    var el = document.createElement('input');
    el.type = 'text';
    el.name = 'tag[]';
    el.id = 'tag' + iteration;
    el.size = 15;
    newCell1.appendChild(el);
    }
    
    function deleteRows(tblId)
    {
    var tbl = document.getElementById(tblId);
    var i=tbl.tBodies[0].rows.length-1; {
    tbl.tBodies[0].deleteRow(i);
    }
    }</script>
    </head>
    
    <body>
    
    <form action="storyinsert.php" method="post">
    Title: <input type="text" name="title" /><br>
    Contributed By: <input type="text" name="contributed_by" /><br>
    Name: <input type="text" name="name" /><br>
    Content: &nbsp;<TEXTAREA NAME="content" ROWS="10", COLS="30">Your data</TEXTAREA><br>
    Moral: <input type="text" name="moral" /><br>
    
    <a name="tag" onClick="insertRowPHP();" href="#">Add Tag</a>
    <a name="tag" onClick="deleteRows('tblInsertRowPHP');" href="#">Remove Tag</a><br>
    
    <table border="0" cellspacing="0" id="tblInsertRowPHP">
    <thead>
    <tr>
    <th colspan="2">tblInsertRowPHP header</th>
    
    </tr>
    </thead>
    <tbody></tbody>
    </table>
    
    <?php
    
    $value = addslashes(serialize($tag));
    
    ?>
    
    Category: <select name="category">
    <option value="Chocolate Pie">Chocolate Pie</option>
    <option value="It's Him">It's Him</option>
    <option value="Mixed Bag">Mixed Bag</option>
    <option value="Director's Cut">Director's Cut</option>
    <option value="Tickle Your Bone">Tickle Your Bone</option>
    <option value="The Living Legends">The Living Legends</option>
    <option value="Rhythm n Blue">Rhythm n Blue</option>
    <option value="Tiny Thoughts">Tiny Thoughts</option>
    </select><br>
    Choose The Mood:
    <input type="radio" name="mood" value="Cheerful" checked> Cheerful <input type="radio" name="mood" value="Confused"> Confused <input type="radio" name="mood" value="Sad"> Sad <input type="radio" name="mood" value="Anxious"> Anxious <input type="radio" name="mood" value="Laughing"> Laughing
    <input type="radio" name="mood" value="Surprised"> Surprised<br>
    <input type="submit" />
    <?php
    $date = mktime(date("G"), date("i"), date("s"), date("m"), date("d"), date("Y"));
    echo date("d/m/Y G:i:s", $date);
    ?>
    <input type="hidden" name="date" value="<?php echo date("d/m/Y G:i:s", $date);?>" />
    <input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR'];?>" />
    </form>
    </body>
    </html>
    Last edited by krishnakhanna; Aug 18, 2007 at 10:55.


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
  •