Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    2

    Question Unanswered: Edit and Delete Facility for a simple News Script

    First I'll outline what I'm working with:

    I've been Messing around with PHP and Mysql for about 3 day (Looking at tutorials, Trial and error, Self Learning in a way) and have built a Simple news Script, but... I've been wondering if I could take it one step further (Eg: by adding a edit facility and a delete).

    Here's the script so far:

    ::news.php::
    PHP Code:
    <?
    include("dbconnect.php");
    $getnews mysql_query("select * from news ORDER BY id DESC");
    while(
    $r=mysql_fetch_array($getnews)){
    extract($r);
    echo(
    "<table width='600' border='2' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000'>
      <tr> 
        <td width='500'><font face='arial' size='2' color='#4C77B6'><b><u>
    $title</u></b></font><br/>
          <font face='arial' size='2' color='#000000'><b></b></font> </td>
        <td width='100'><font face='arial' size='2' color='#000000'><b>
    $date</b></font></td>
      </tr>
      <tr> 
        <td colspan='2'><font face='arial' size='2' color='#000000'><b>
    $news</b></font></td>
      </tr>
    </table><br>"
    );

    }
    ?>
    ::addnews.php::
    Code:
    <html>
    <head>
    <title>Add News Section</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <form action="submit.php" method="post">
    <b>Title</b>
    <BR />
    <input type="text" name="title" size="40" maxlength="80" value="" />
    <br />
    <br />
    <b>News</b><BR><textarea name="news" rows="3" cols="40"></textarea>
    <br />
    <br />
    <input type="submit" value="submit" /> <input type="reset" value="reset" />
    </form>
    </body>
    </html>
    ::submit.php::
    PHP Code:
    <?
    //gets mysql info
    include("dbconnect.php");
    //gets the current date...
    $date date("j F");
    $addnews =MYSQL_QUERY("INSERT INTO news (id,title,date,news)""VALUES ('NULL', '$title', '$date', '$news')");
    //success...
    echo("News Added!");
    ?>
    ::dbconnect.php::
    PHP Code:
    <?
    mysql_connect
    ("localhost","username","password"); 
    mysql_select_db("databasename");
    ?>
    It's Simple... but an arse ache to go into the Database an rip out the posts I want deleted

    If anyone could help out.. or indeed point me to a good tutorial.. I would Greatly appreciate it
    Last edited by Quisk; 03-15-04 at 09:14.

  2. #2
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61
    Well heres some other sql statements that might help.

    EDITING A DB:
    $query = "UPDATE $table SET field_one='1', field_two='2' WHERE row_id='1'";
    mysql_query($query);

    DELETING FROM A DB:
    $query = "DELETE FROM $table WHERE row_id='1'";
    mysql_query($query);
    Mr. Lars

Posting Permissions

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