SitePoint Sponsor

User Tag List

Page 3 of 7 FirstFirst 1234567 LastLast
Results 51 to 75 of 151
  1. #51
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    she will be my first chose.

    thanks spikeZ for joining
    will you care to share your expertise ?

    jelena ill say this to you thanks for all the help specially the diffrent methods
    you tought me i apriciated.
    however, if this is a project for money i will not mind sharing part of the profit
    after all the porpose of community is to help each othere and learn from each other
    right spikeZ ?

    any way may be one day all be teaching begginers even if the Qs were silly like my
    Qs corrently.

  2. #52
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Don't worry hisham, we are all here to learn! I was just kidding and Jelena is a great teacher
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #53
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    indeed she is.

    thanks spikeZ

  4. #54
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would you help me please
    am trying to delete a record.!
    it display
    Records deleted: %d 0
    29

    the address bar
    http://localhost/Practise/test2/dele...?article_ID=29
    for me the code looks ok
    PHP Code:
     <?php
     
     
    include "connect.php";
         
         
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('connecting to MySQL failed');
         
    mysql_select_db($dbname);
     
     
     
    $article_id $_GET['article_ID'];
     
     
    $sql 'DELETE FROM articles WHERE articleID = "$article_id" ';
         
    mysql_query($sql) or die(mysql_error());
       
    //i got this from the manual  
     
    echo ("Records deleted: %d\n"mysql_affected_rows());
     
     echo 
    '<br />';
     echo 
    $article_id;
     
     
    ?>

  5. #55
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Here you go
    PHP Code:
    $sql "DELETE FROM articles WHERE articleID = '".$article_id."'";
     
    mysql_query($sql) or die(mysql_error());
       
    //i got this from the manual  
    echo ("Records deleted:".$article_id); 
    Also, thanks for the kind words to both of you
    -- Jelena --

  6. #56
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its working heeeha

    i cant belive my self.

    ahhh i need practise and practise so i will not do such mistakes
    . .

    about the word thats the less i can do at the corrent time

  7. #57
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you know any tutorials or may be example that can learn how to direct
    the admin
    example
    when the admin click delete it goes to a page stating this record hase been
    deleted and in may be a timer of 5secound he goes to the display page
    which he can delete or edit the records

    i tryed posting a link in the delete page but when i click the page do not
    refresh is this becouse am using localhost ?

  8. #58
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    why don't you just show him a link
    Code:
    <a href="article_list.php">Back to list of articles</a>
    Or even go with back button
    Code:
    <a href="" onclick="history.go(-1);">Go Back</a>
    -- Jelena --

  9. #59
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually thats what i did i just thouht may be there is
    othere way to go around it.

    Or even go with back button
    Code:
     <a href="" onclick="history.go(-1);">Go Back</a>
    first time i see this what exactly it does

  10. #60
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the Read code
    but it does not display the Date !?
    is there a special way to get the date from the DB.
    Notice: Undefined variable: row in E:\Practise\test2\read.php on line 68

    PHP Code:
    include "connect.php";
        
        $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
        mysql_select_db($dbname);


    $article_id = $_GET['article_ID'];

    $sql = "SELECT * FROM articles WHERE articleID = '".$article_id."'";
    mysql_query($sql) or die(mysql_error());
    $res = mysql_query($sql);
    $num = mysql_fetch_row($res);
    if (!$res) {
       echo 'Could get record: ' . mysql_error();
       exit;
    }

    /*
    echo $row[0]; // atticle id
    echo $row[1]; // article name
    echo $row[2]; // summary
    echo $row[3]; // author
    echo $row[4]; // content
    echo $row[5]; // notes
    echo $row[6]; //date added
    echo $row[7]; //status
    */
    ?>

    <table width="720" border="1" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="181" height="30" valign="top">Name </td>
        <td width="539" valign="top"><?php echo $num[1]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Summary</td>
        <td valign="top"><?php echo $num[2]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Author</td>
        <td valign="top"><?php echo @$num[3]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Content</td>
        <td rowspan="2" valign="top"><?php echo $num[4]; ?></td>
      </tr>
      <tr>
        <td height="190">&nbsp;</td>
      </tr>
      <tr>
        <td height="42" valign="top">Note</td>
        <td valign="top"><?php echo @$row[5]; ?></td>
      </tr>
      
      <tr>
        <td height="30" valign="top">Date added </td>
        <td valign="top"><?php echo $row[6]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Status</td>
        <td valign="top"><?php echo @$row[7]; ?></td>
      </tr>
    </table>
    <?php mysql_close($conn); ?>

  11. #61
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    try this out. I prefer using mysql_fetch_assoc really.
    PHP Code:
    include "connect.php";
        
        $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
        mysql_select_db($dbname);


    $article_id = $_GET['article_ID'];

    $sql = "SELECT * FROM articles WHERE articleID = '".$article_id."'";
    mysql_query($sql) or die(mysql_error());
    $res = mysql_query($sql);
    $num = mysql_fetch_assoc($res);
    if (!$res) {
       echo 'Could get record: ' . mysql_error();
       exit;
    }
    ?>

    <table width="720" border="1" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="181" height="30" valign="top">Name </td>
        <td width="539" valign="top"><?php echo $num["article_name"]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Summary</td>
        <td valign="top"><?php echo $num["summary"]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Author</td>
        <td valign="top"><?php echo $num["author"]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Content</td>
        <td rowspan="2" valign="top"><?php echo $num["content"]; ?></td>
      </tr>
      <tr>
        <td height="190">&nbsp;</td>
      </tr>
      <tr>
        <td height="42" valign="top">Note</td>
        <td valign="top"><?php echo $row["article_note"]; ?></td>
      </tr>
      
      <tr>
        <td height="30" valign="top">Date added </td>
        <td valign="top"><?php echo $row["date_added"]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Status</td>
        <td valign="top"><?php echo $row["status"]; ?></td>
      </tr>
    </table>
    <?php mysql_close($conn); ?>

    If date still doesn't want to display, try to do
    PHP Code:
    var_dump($num); 
    after fetching the data and let me know the results.
    -- Jelena --

  12. #62
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for empty fields in the database i get this errors
    line 56 in the date
    Notice: Undefined variable: row in E:\Practise\test2\read.php on line 51
    Notice: Undefined variable: row in E:\Practise\test2\read.php on line 56
    Notice: Undefined variable: row in E:\Practise\test2\read.php on line 60

  13. #63
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var_dump() is very intersting

    it gives me

    array(8) { ["articleID"]=> string(1) "9" ["article_name"]=> string(10) "xcnvdmjdgm" ["summary"]=> string(12) "dmhsdkmgdgmk" ["author"]=> string(11) "dgjmdghjmdg" ["article_content"]=> string(13) "dghmhjmhklto;" ["notes"]=> string(5) "dgmdg" ["date_added"]=> string(15) "Sun-26-Mar-2006" ["status"]=> string(1) "0" }

  14. #64
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    include "connect.php";
        
        
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('connecting to MySQL failed');
        
    mysql_select_db($dbname);


    $article_id $_GET['article_ID'];

    $sql "SELECT * FROM articles WHERE articleID = '".$article_id."'";
    mysql_query($sql) or die(mysql_error());
    $res mysql_query($sql);
    $num mysql_fetch_assoc($res);
    if (!
    $res) {
       echo 
    'Could get record: ' mysql_error();
       exit;
    }
    ?>

    <table width="720" border="1" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="181" height="30" valign="top">Name </td>
        <td width="539" valign="top"><?php echo $num["article_name"]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Summary</td>
        <td valign="top"><?php echo $num["summary"]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Author</td>
        <td valign="top"><?php echo $num["author"]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Content</td>
        <td rowspan="2" valign="top"><?php echo $num["article_content"]; ?></td>
      </tr>
      <tr>
        <td height="190">&nbsp;</td>
      </tr>
      <tr>
        <td height="42" valign="top">Note</td>
        <td valign="top"><?php echo $num["notes"]; ?></td>
      </tr>
      
      <tr>
        <td height="30" valign="top">Date added </td>
        <td valign="top"><?php echo $num["date_added"]; ?></td>
      </tr>
      <tr>
        <td height="30" valign="top">Status</td>
        <td valign="top"><?php echo $num["status"]; ?></td>
      </tr>
    </table>
    <?php mysql_close($conn); ?>
    Variable name was wrong! It should be $num, not $row on those lines.
    -- Jelena --

  15. #65
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its fully functional thanks to you
    i been 11 stight infront of the computer
    my right eaye down see thinks clear any more my time is up.

    thanks agine
    take care

  16. #66
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You are really welcome

    Let me know if you find problems with edit function.
    -- Jelena --

  17. #67
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there lovely morning in south east asia today

    ok this morning i started working on the edit part and i came up with this
    i know its not that efficient, may be all inhance it slowly.
    comment on it please.
    edit1
    PHP Code:


    <?php 
    include "connect.php";
        
        
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('connecting to MySQL failed');
        
    mysql_select_db($dbname);


    $article_id $_GET['article_ID'];

    $sql "SELECT * FROM articles WHERE articleID = '".$article_id."'";
    mysql_query($sql) or die(mysql_error());
    $res mysql_query($sql);
    $num mysql_fetch_assoc($res);
    if (!
    $res) {
       echo 
    'Could get record: ' mysql_error();
       exit;
    }
       
    ?>
    <form action="edit2.php" method="post">
      Article ID <br />
      <input name="articleid" type="text" id="articleid" value="<?php echo $num["articleID"];?>" size="15" maxlength="15" />
      <br />
      Article Name <br />
      <input name="articlename" type="text" id="articlename" value="<?php echo $num["article_name"];?>" size="80" maxlength="80" />
      <br />
      Summary <br />
      <textarea name="summary" cols="50" rows="3" wrap="physical" id="summary"><?php echo $num["summary"];?>
    </textarea>
      <br />
      Author <br />
      <input name="author" type="text" id="author" value="<?php echo $num["author"];?>" size="50" maxlength="50" />
      <br />
      Article Content <br />
      
      <textarea name="articlecontent" cols="100" rows="20" wrap="physical" id="articlecontent"><?php echo $num["article_content"];?></textarea>
      <br />
      Notes <br />
      
      <textarea name="notes" cols="50" rows="3" wrap="physical" id="notes"><?php echo $num["notes"];?></textarea>
      <br />
      Date Posted <br />
      <input name="date" type="text" id="date" value="<?php echo $num["date_added"];?>" size="30" maxlength="30" />
      <br />
      Status <br />
      <input name="status" type="text" id="status" value="<?php echo $num["status"];?>" size="30" maxlength="30" />
      <br />
      <input name="" type="submit" value="Submit" />
    </form>
    <?php

     mysql_free_result
    ($res);
        
        
    mysql_close($conn);
    ?>
    edit2
    PHP Code:
    <?php 
    include "connect.php";
        
        
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('connecting to MySQL failed');
        
    mysql_select_db($dbname);
        
        
    $article_id $_POST['articleid'];
        
    $articlename $_POST['articlename'];
        
    $summary $_POST['summary'];
        
    $author $_POST['author'];
        
    $articlecontent $_POST['articlecontent'];
        
    $notes $_POST['notes'];
        
    $status $_POST['status'];
    $sql "UPDATE articles "."SET article_name = '$articlename', 
                                    summary = '
    $summary', 
                                    author = '
    $author',
                                     article_content='
    $articlecontent', 
                                     notes='
    $notes', status = '$status'"
                         
    "WHERE articleID = '$article_id'";

    mysql_query($sql) or die(mysql_error());



    $res mysql_query($sql);
    if (!
    $res) {
       echo 
    'Could get record: ' mysql_error();
       exit;
    }else {echo 
    'OK';}
    mysql_close($conn);
    ?>

  18. #68
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello there

    No, actually your edit is quite fine. There are few things I would change:
    I would put articleid as hidden field in a form like:
    PHP Code:
     <input name="articleid" type="hidden" id="articleid" value="<?php echo $num["articleID"];?>" />
    The other thing is that I would check if all required fields are empty, just to prevent admin to delete something.
    -- Jelena --

  19. #69
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there i hope you are having a lovely day in country ?
    all do that thanks for remainding me on that, its going to be a mess
    if the admin change the id number.

    i think this is the simplest article system ever been done with PHP

    i have one q if i want to implement authontication on this script
    how do i go about it.

    shall i use DB or just text file to store
    shall i think of encription shall i put the user name and passward in
    the script it self. may be session.?

    what would you do if your in my place (your Profissional opinion) please.?

    thanks'

  20. #70
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If we are talking about protecting admin area, I would go with htaccess to protect administration section (if it's available on a server).
    -- Jelena --

  21. #71
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Also, next stage would be for you to create functions which will perform various actions. For example, you could create a function for adding new article, place it in separate file and include it where it is needed.
    I would also create a configuration file where I would put various configuration setting like DB details for example, definitions of paths, urls etc..

    Give me some time, and I'll show you an example.
    -- Jelena --

  22. #72
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    according to http://en.wikipedia.org/wiki/Htaccess
    its apache server (i never tryed Apache server) feature which make you setup the directory permission
    and ofcorse many othere features like block serten IP addreses and the list go own
    its a big scop topic to study with my corrent position in PHP.
    i was thinking of something simpler. may be session

    Do you know any good tutorials for begginers about sessions.?

  23. #73
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    reading more about it its very handy for security.

  24. #74
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Let me explain what I have mentioned in my previous post.
    This would be next stage of creating your project little bit in order.
    This is also a basic concept but you should get an idea:
    I will add 3 more files: functions.php, config.php, common.php
    firstly config.php
    PHP Code:
    <?php

    //db settings
     
    define("BASESERVER","localhost");
    define("BASEUSER","roots");
    define("BASEPASS""555456");
    define("BASENAME","site"); 

    ?>
    For now it's very bacis, it only holds database settings, but later you can add some global settings you need everywhere.
    common.php
    PHP Code:
    <?php
    include_once "config.php";
    include_once 
    "functions.php";
    session_start();

    //connect to the base
    if(!($db = @mysql_pconnect(BASESERVERBASEUSERBASEPASS)))    //connect to base host
        
    die("Cannot connect to the base server.");
    if(!@
    mysql_select_db(BASENAME,$db))    //select base
        
    die("Database doesn't exist!!!");
        
        
    //common functions
    function my_query($sql)
    {
        GLOBAL 
    $_SERVER["PHP_SELF"];
        GLOBAL 
    $db;

        if((
    $result = @mysql_query($sql,$db)) == 0)      //Execute SQL query
        
    {
            echo 
    "\n<hr>Database error: <strong>".mysql_error()."</strong><br /><br />\n";
            die(
    "Query was (<strong>$sql</strong>) in file <strong>".$_SERVER["PHP_SELF"]."</strong>");
        }
        else
            return 
    $result;
    }
    ?>
    As you can see, common will include config and functions, start session and connect to database. Some people are against persistant connections to database, but I have never had problems with them in my life.
    Also, you will notice my_query function which basically execute the given query. You will probably find id handy later on.
    And functions.php
    PHP Code:
    /**
    *
    *    Simple function for adding article
    *
    *    Function expects an array with article details
    *    it will perform all neccesary checks 
    *    On error it will set session with error and return false
    *    On success, it will add record into database and return true
    *
    */
    function article_add($data)
    {
        if(empty(
    $data["article_name"]))
        {
            
    $_SESSION["error"] = "Please enter The Article Name";
            return 
    false;
        }
        else if(empty(
    $data["summary"]))
        {
            
    $_SESSION["error"] = "Please enter a summary";
            return 
    false;
        }
        else if(empty(
    $data["article_content"]))
        {
            
    $_SESSION["error"] = "Please enter a content";
            return 
    false;
        }
        
        
    $sql "INSERT INTO articles SET";
        
    $sql .= " article_name = '".$data["article_name"]."'";
        
    $sql .= ", summary = '".$data["summary"]."'";
        
    $sql .= ", author = '".$data["author"]."'";
        
    $sql .= ", article_content = '".$data["article_content"]."'";
        
    $sql .= ", notes = '".$data["notes"]."'";
        
    $sql .= ", date_added = NOW()";
        
    $sql .= ", Status = '0'"

        
    my_query($sql);
        return 
    true;

    For now, functions file have this simple function which will add article in database.
    Now, your file which adds article in database should look like this:
    PHP Code:
    <?php

        
    include_once "common.php";

        
    $article["article_name"]   = $_POST['articlename'];
        
    $article["summary"] = $_POST['summary'];
        
    $article["author"]   = $_POST['author'];
        
    $article["article_content"] = $_POST['bodycontent'];
        
    $article["notes"] = $_POST['notes'];
        
        if(
    article_add($article))
        {
            
    //success
            //do whatever you want to do on succes
        
    }
        else
        {
        
    //error
        
    $_SESSION["article"] = $article;
            
    header("Location: add11.php");
        }
    ?>
    This way you will have to include common.php in every file, but it really makes it easier this way.

    This is first stage of course, and lots of changes can be done to all those files, but it's wise to go step by step

    As for the sessions, they are good for usage for logging in users, but you should firstly decide where would you like to store username/password. I suggested htacces because it's the easiest way and it's just fine for the start.
    Last edited by jelena; Mar 30, 2006 at 08:10. Reason: fixed syntax error..
    -- Jelena --

  25. #75
    SitePoint Guru hisham777's Avatar
    Join Date
    Dec 2005
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    clean Code, it make me realise am at level 7 of 100 in PHP
    but thats will not stop me.

    Quote Originally Posted by jelena
    As for the sessions, they are good for usage for logging in users, but you should firstly decide where would you like to store username/password. I suggested htacces because it's the easiest way and it's just fine for the start.
    my idea to have one persone that admin the articles, and what
    i understand from htacces its for apache servers, what about
    IIS, if can do in ISS as well please point me to a tutorial.
    i dare not ask you more about article system after i saw your code
    you done alot .


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
  •