SitePoint Sponsor

User Tag List

Page 1 of 7 12345 ... LastLast
Results 1 to 25 of 151
  1. #1
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question simple Article system Development

    hello everybody

    i know for some it my sound very simple and silly
    am trying to do a simple article system am in my planning stage
    i hope i can learn from the community in SP.

    the features in the article system are add, edit, delete and a simple authontication.

    Admin side will be
    To add, edit, delete

    the add and edit its just a forms with filds (No smilies, links, Formaiting)
    article name, Short name, Summary, Date, Article body and admin notes

    User side will be
    one page to see the latests 3 article (name and summary)
    one page for the article
    one page for the archive


    The table

    ID (Uniqe, Auto increment, Primary key)
    aricle_name (Char)
    Short_name (Char)
    Date (Timestamp)
    body_text (text)
    Note (text)


    this is my first step, comment on it is appriciated

    My secound step will be coding the admin page (ist right)
    Or shall i start with the display page


    it can be a point of start for alote of begginers
    help and comments are appriciated
    thanks in advance

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It's a good start!
    You forgot a field for Summary in your db table.
    Other then that, everything looks just fine.

    You should start to code admin page firstly. Add/edit/delete features before you go to listing part in front-end. At least, I would do it first. And while you are finished with that, you'll have data in your table to play with while creating front-end.
    -- Jelena --

  3. #3
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for reply

    all do that once its done all post the code her for comments before i
    start with the display page

    thanks again

  4. #4
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Date (Timestamp)

    this fild should be auto date
    what i mean the admin do not need to write the date
    i want to add small php code to get the time and date the submite it to the table

    any help on how to do that
    how to go about it

    thanks

  5. #5
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You have mysql function to do that for you
    Code:
    INSERT INTO your_table SET
    date_column = NOW()
    -- Jelena --

  6. #6
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks jelena you been i good help

  7. #7
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi again am still in the design phase of the add new article page
    and i came across validation issue of the content that its going to be
    submited.

    there are many ways to do that.

    php is a server side script, so programmer will chose client side coding
    like jave script to validate the content(i think)

    in my case i dont know anything about java script i mean coding

    so this idea came across my mind
    the code will be like this
    step 1 HTML form to input the content
    step 2 php will get the code and dump it in a text file
    step 3 php read the file and display it to the admin and ask for confirmation
    if yes the data will be submited to the database and the text file will
    be empted.

    is this a right way to implement it or there are other approches better and
    i dont know may be easyer

    thanks for the help

    note: i hope there will be an article on SP on how to create a simple article
    system using PHP

  8. #8
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no body is botherd!!!! i hope am not bricking any SP rules ??

  9. #9
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Or, you can insert data in the db after submittion, and have one more field in table which will indicate the status of submitted article.

    Status tinyint
    When article is submitted, Status will be 0 which will indicate that it has not been approved by admin. Once the admin approves it, you just update Status column for that article and set it to 1.
    When displaying articles in the front-end, just fetch those which has Status set to 1.
    -- Jelena --

  10. #10
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    very good idea
    in this case i dont need to write a varify code cool

    by any chance do you know any tutorial regarding this
    or may be a snap code


    thanks in advance

  11. #11
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok jelena i have followed your advice thank you for it.

    The database structure is in the attachment

    this is the form code

    HTML Code:
    <form method="post" action="addarticle1.php">
    <p>Article Name:</p>
    <input name="articlename" type="text" size="80" maxlength="80" id="articlename" />
    <p>Summary:</p>
    <textarea name="summary" cols="50" rows="3" wrap="physical" id="summary"></textarea>
    <p>Author: </p>
    <input name="author" type="text" id="author" size="50" maxlength="50" />
    <p>Body Content:</p>
    <textarea name="bodycontent" cols="100" rows="20" wrap="physical"></textarea>
    <p>Note:</p>
    <textarea name="notes" cols="50" rows="3" wrap="physical"></textarea>
    <br /><br />
    <input name="add" type="submit" value="send" />
    </form>
    and this is the PHP code (Add new article)

    PHP Code:
    <?php
          $dbhost 
    'localhost';
        
    $dbuser 'roots';
        
    $dbpass '555456';
        
    $dbname 'site';
        
        
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('connecting to MySQL failed');
        
    mysql_select_db($dbname);

        
    $article_name   $_POST['articlename'];
        
    $summary $_POST['summary'];
        
    $author   $_POST['author'];
        
    $article_content $_POST['bodycontent'];
        
    $notes $_POST['notes'];
        
    $date_added =date("D",time()) . "-" date("d",time()) . "-" date("M",time()) . "-" date("Y",time()); 

        
    $query "INSERT INTO articles VALUES (NULL, '$article_name', '$summary', '$author', '$article_content', '$notes', '$date_added', '0')";
        
        
    mysql_query($query) or die(mysql_error());
            
        
    mysql_close($conn);
        
    //just for debuging. to see is the variables are passed or not
        
    echo $article_name;
        echo 
    $summary;
        echo 
    $author;
        echo 
    $article_content;
        echo 
    $notes;
        echo 
    $date_added;
    ?>

    please comment on the code

    is this correct way of implementing ?
    is the database structure fine ?
    are there any issues.security may be ?

    am biggener, help appriciated specially from Pros out there
    Attached Images Attached Images

  12. #12
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    While waiting for attachment to be approved, I can add few more notes on code.

    It's looking good. What I would add are few more checkes. I would check if entries from form are empty, if so, I would notify a user about that and won't allow data to get inserted in db if he hasn't entered all details needed. Also, I would change the way date is handled (just like I already told you).. I would use mysql function NOW() rather then create date the way you did.
    -- Jelena --

  13. #13
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes jelena thanks for reply
    about the date am too new to MySQL
    the statement you gave me i did not know how to use it
    you may feel surprese, and say how come its to simple and stright forward.
    but with my basic knowlage of PHP and MySQL . using the Date function is my chose becouse its what i know how to use at the moment ,
    and i did not want the time to change everytime the article updated (if my understanding of function NOW() correct).
    i hope i explended in the right way

  14. #14
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry my bad

    the new code
    PHP Code:
    <?php
          $dbhost 
    'localhost';
        
    $dbuser 'roots';
        
    $dbpass '555456';
        
    $dbname 'site';
        
        
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('connecting to MySQL failed');
        
    mysql_select_db($dbname);

        
    $article_name   $_POST['articlename'];
        
    $summary $_POST['summary'];
        
    $author   $_POST['author'];
        
    $article_content $_POST['bodycontent'];
        
    $notes $_POST['notes'];
        
    //$date_added =date("D",time()) . "-" . date("d",time()) . "-" . date("M",time()) . "-" . date("Y",time()); 

        
    $query "INSERT INTO articles VALUES (NULL, '$article_name', '$summary', '$author', '$article_content', '$notes', NOW(), '0')";
        
        
    mysql_query($query) or die(mysql_error());
            
        
    mysql_close($conn);
        
        echo 
    $article_name;
        echo 
    $summary;
        echo 
    $author;
        echo 
    $article_content;
        echo 
    $notes;
        
    //echo $date_added;
    ?>

  15. #15
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It looks better .
    Now it's the time for you to implement some checks upon form fields.
    -- Jelena --

  16. #16
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok about form checks fields

    in the article system there must be a title, summary, and the content
    as for the rest of the fields are up to the admin to add.
    base on this i think i have noticed a function in PHP to check empty fields
    if am not mistaking using IF statment i have to go to the manual for that

    thanks jelena so far you are the only one helping me on this Appriciated

  17. #17
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This is how your ddarticle1.php should look like:
    PHP Code:
    <?php

    session_start
    ();

        
    $article["article_name"]   = $_POST['articlename'];
        
    $article["summary"] = $_POST['summary'];
        
    $article["author"]   = $_POST['author'];
        
    $article["article_content"] = $_POST['bodycontent'];
        
    $article["notes"] = $_POST['notes'];
        
        if(empty(
    $article["article_name"]) || empty($article["summary"]) || empty($article["article_content"]))
        {
            
    $_SESSION["article"] = $article;
            
    $_SESSION["error"] = "Please enter title, summary and the content";
            
    header("Location: form.php");
            exit;
        }

        
    $dbhost 'localhost';
        
    $dbuser 'roots';
        
    $dbpass '555456';
        
    $dbname 'site';
        
        
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('connecting to MySQL failed');
        
    mysql_select_db($dbname);


        
    $query "INSERT INTO articles VALUES (NULL, '."$article["article_name"]."', '".$article["summary"]."', '".$article["author"]."', '".$article["article_content"]."', '".$article["notes"]."', NOW(), '0')";
        
        
    mysql_query($query) or die(mysql_error());
            
        
    mysql_close($conn);
        
        echo 
    $article_name;
        echo 
    $summary;
        echo 
    $author;
        echo 
    $article_content;
        echo 
    $notes;
        
    //echo $date_added;
    ?>
    And form file:
    PHP Code:
    <?php
    session_start
    ();

    if(isset(
    $_SESSION["article"]))
    {
        
    $article $_SESSION["article"];
        unset(
    $_SESSION["article"]);
    }

    if(isset(
    $_SESSION["error"]))
    {
        
    $error $_SESSION["error"];
        unset(
    $_SESSION["error"]);
    }

    ?>

    <?php
    if(isset($error))
    {
        
    ?>
        <div><?php echo $error;?></div>
        <?php
    }
    ?>

    <form method="post" action="addarticle1.php">
    <p>Article Name:</p> <input name="articlename" type="text" size="80" maxlength="80" id="articlename" value="<?php if(isset($article["article_name"])) echo $article["article_name"];?>" /> 
    <p>Summary:</p> <textarea name="summary" cols="50" rows="3" wrap="physical" id="summary"><?php if(isset($article["summary"])) echo $article["summary"];?></textarea> 
    <p>Author: </p> <input name="author" type="text" id="author" size="50" maxlength="50" value="<?php if(isset($article["author"])) echo $article["author"];?>" /> 
    <p>Body Content:</p> <textarea name="bodycontent" cols="100" rows="20" wrap="physical"><?php if(isset($article["article_content"])) echo $article["article_content"];?></textarea> 
    <p>Note:</p> <textarea name="notes" cols="50" rows="3" wrap="physical"><?php if(isset($article["notes"])) echo $article["notes"];?></textarea> 
    <br /><br /> 
    <input name="add" type="submit" value="send" /> </form>
    I haven't tested the code, but you should get a basic idea how to check if user has inputed everything that is needed as well as populating form with previously entered data.
    -- Jelena --

  18. #18
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jelena thats alot
    there are alot of the code i dont understand
    i have to study the code
    I cant at the moment i have a class gtg
    thanks

  19. #19
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Just let me know which parts require further explanation
    -- Jelena --

  20. #20
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i start reading about sessions in this site
    http://www.hudzilla.org/phpbook/read.php/10_0_0

    and i get to tell you from what am reading its easy and very usefull

    now i need to read more about isset()

  21. #21
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    may be you can help me in directing me to some tutorials about isset() and its use.
    according to the manual, after php3 its no more a function !.

    thanks in advince

  22. #22
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok her is the thing
    addarticle code is stright
    start the session
    get values
    check if one of the three filds empty
    if yes go back to the form and fill it

    else
    go connect to DB and submit the values (thanks to the manual)

    but for the form code no idea
    would you please explain on may be some comment on
    the code thanks

    by the way i get this error when i run the form code

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\Practise\issettest.php:9) in E:\Practise\issettest.php on line 10

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\Practise\issettest.php:9) in E:\Practise\issettest.php on line 10


    Note: i think that the addarticle.php does the job

  23. #23
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You will have to post your code, so I could find the error. There shouldn't be any blank HTML lines above the session_start, which might cause Warning you are getting.

    issset() is no longer function, but it's language construct. That only means it cannot be called using variable functions.
    -- Jelena --

  24. #24
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the code is working perfectly thanks to you jelena
    even though am still not confitable with the session.

    i added simple massage
    PHP Code:
    session_start();

        
    $article["article_name"]   = $_POST['articlename'];
        
    $article["summary"] = $_POST['summary'];
        
    $article["author"]   = $_POST['author'];
        
    $article["article_content"] = $_POST['bodycontent'];
        
    $article["notes"] = $_POST['notes'];
        
        if(empty(
    $article["article_name"]))
        {
            
    $_SESSION["article"] = $article;
            
    $_SESSION["error"] = "Please enter The Article Name";
            
    header("Location: add11.php");
            exit;
        }
        else if(empty(
    $article["summary"]))
        {
            
    $_SESSION["article"] = $article;
            
    $_SESSION["error"] = "Please enter a summary";
            
    header("Location: add11.php");
            exit;
        }
        else if(empty(
    $article["article_content"]))
        {
            
    $_SESSION["article"] = $article;
            
    $_SESSION["error"] = "Please enter a content";
            
    header("Location: add11.php");
            exit;
        }
        
    $dbhost 'localhost';
        
    $dbuser 'roots';
        
    $dbpass '555456';
        
    $dbname 'site';
        
        
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('connecting to MySQL failed');
        
    mysql_select_db($dbname);


        
    $query "INSERT INTO articles VALUES (NULL, 
        '"
    .$article["article_name"]."', 
        '"
    .$article["summary"]."', 
        '"
    .$article["author"]."', 
        '"
    .$article["article_content"]."', 
        '"
    .$article["notes"]."', 
        NOW(), 
        '0')"
    ;
        
        
    mysql_query($query) or die(mysql_error());
            
        
    mysql_close($conn);
        
        
        
        echo 
    $article["article_name"];
        echo 
    $article["summary"];
        echo 
    $article["author"];
        echo 
    $article["article_content"];
        echo 
    $article["notes"];
        
    /*
        echo $article_name;
        echo $summary;
        echo $author;
        echo $article_content;
        echo $notes;
        //echo $date_added;
        */
    ?> 

  25. #25
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think the baise of the add page is ok
    now all start with display and delete pages ?
    what do you think.?


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
  •