SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Add Edit Delete mysql with flash

    I am trying to make an online tool that you can log into, and make simple posts with....and I want to be able to edit these posts, or delete these posts that only you have posted,And I want an item search also for finding the items that you want to buy, that other people have posted, but you can't edit using a login.

    And I want to do this all in flash, which I know is possible..

    I have aim it is:surname45 if that helps you contact me with help!!



    someone else has posted this script I hope I can edit to use (but I only just learned how to make a mysql database and to contact the information with rudimentary php);







    molder101
    posted this;





    <?

    // Define MYSQL Connection
    define ('MYSQL_HOST', 'localhost');
    define ('MYSQL_USER', 'user');
    define ('MYSQL_PASS', 'pass');
    define ('MYSQL_DB', 'boy');

    // Try to connect to the DB
    if (! mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) )
    {
    echo 'Failed to connect to: "On This Day Database."';
    exit;
    }

    // Select the appropriate db
    mysql_select_db(MYSQL_DB);

    // Define date variables
    $m=date("F");
    $d=date("d");

    // Check to see if form was self-submitted
    if ($HTTP_POST_VARS['do']=='submit')
    {
    submit_edit($HTTP_POST_VARS);
    }
    else
    {
    // Add the passed data (if any) to fill the form
    db_filldata($id);
    show_edit_form($entry);
    }

    function show_edit_form($entry)
    {
    $id = $entry[0];
    $month = $entry[1];
    $day = $entry[2];
    $year = $entry[3];
    $content = $entry[4];
    $link = $entry[5];
    $date_added = $entry[6];
    ?>

    <b>
    <form method="POST" action='<? echo $PHP_SELF ?>' name="edit_form">
    <input type="hidden" name="do" value="submit">

    Entry ID: <? echo $id ?><br>
    Date Entered: <? echo date("F d, Y - h:iA", $date_added) ?><p>
    </b>

    Monthbr>
    <select name="month" value="<? echo $month ?>">
    <option value="January"<? if ($month=="January") { echo " selected"; } ?>>January</option>
    <option value="February"<? if ($month=="February") { echo " selected"; } ?>>February</option>
    <option value="March"<? if ($month=="March") { echo " selected"; } ?>>March</option>
    <option value="April"<? if ($month=="April") { echo " selected"; } ?>>April</option>
    <option value="May"<? if ($month=="May") { echo " selected"; } ?>>May</option>
    <option value="June"<? if ($month=="June") { echo " selected"; } ?>>June</option>
    <option value="July"<? if ($month=="July") { echo " selected"; } ?>>July</option>
    <option value="August"<? if ($month=="August") { echo " selected"; } ?>>August</option>
    <option value="September"<? if ($month=="September") { echo " selected"; } ?>>September</option>
    <option value="October"<? if ($month=="October") { echo " selected"; } ?>>October</option>
    <option value="November"<? if ($month=="November") { echo " selected"; } ?>>November</option>
    <option value="December"<? if ($month=="December") { echo " selected"; } ?>>December</option>
    </select>
    <p>
    Daybr>
    <select name="day">
    <?
    $i=1;
    while ($i <= 31)
    {
    if ($i==$day)
    {
    echo "<option value=\"$i\" selected>$i</option>\n";
    }
    else
    {
    echo "<option value=\"$i\">$i</option>\n";
    }
    $i++;
    }
    ?>
    </select>
    <p>
    Yearbr>
    <input type="text" name="year" onkeyup="this.value=this.value.replace(/\D/g,'')"

    onchange="this.value=this.value.replace(/\D/g,'')" maxlength="4" size="2" value="<? echo $year ?>">
    <p>
    On This Day Entrybr>
    <textarea rows="10" cols="30" name="content">
    <? echo $content ?>
    </textarea>
    <p>
    Linkbr>
    <input type="text" name="link" value="<? echo $link ?>">
    <p>
    <input type="submit" value="Save Changes" name="submit">
    &nbsp;&nbsp;
    <input type="reset" value="Clear Info" name="reset">
    </form>
    <?
    }

    function db_filldata($value)
    {
    // Send SQL query
    $sql = "SELECT *, UNIX_TIMESTAMP(date_added) AS date_added FROM on_this_day WHERE id = '" . $value . "'";
    $result = mysql_query($sql);

    while ($line = mysql_fetch_array($result)) {
    $id=$line['id'];
    $month=$line['month'];
    $day=$line['day'];
    $year=$line['year'];
    $content=$line['content'];
    $link=$line['link'];
    $date_added=$line['date_added'];

    $entry=array($id,$month,$day,$year,$content,$link,$date_added);
    $GLOBALS['entry'] = $entry;
    }
    }

    function submit_edit($variables)
    {
    mysql_query("UPDATE on_this_day SET month='{$variables['month']}' WHERE id='{$variables['id']}'");
    echo "<font size='4' face='arial'><b>The entry has been updated.</b></font><p>\n";
    echo "<a href='view_day.php' alt='View Entries'>View Entries</a>\n";
    echo "&nbsp;&nbsp;\n";
    echo "<a href='add_day.php' alt='Add Entry'>Add Entry</a>";
    }
    ?>














    sinapra replied;



    you can include all the possible things like, delete, update into one form and on submit can workout with them. What I did is, when you have such a situation and submitting it to the same form, you can add simple 'Button' instead of 'Submit'. Then, the user clicks on a button which would redirect him to the same page, you can set the conditions as per the button he has clicked, say :
    <input type=button name=insert>
    <input type=button name=delete>
    <input type=button name=update>

    Now, on top of the page, you can check for the button which has been clicked,
    if(isset($insert)){
    conditions with queries you want}
    else if(isset($delete)){
    .........}
    and so on.

    I hope that can help you
    __________________
    Regards

    Its Great to work and Be Merry!!!!!!!!
    Last edited by epiphany77; Mar 17, 2007 at 16:23. Reason: small touch up of what I want to get done and to take out faulty links


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
  •