How to Make Bookmark Systems in PHP & MySQL

You can use a PHP page to create a bookmarking system for your website. PHP and MySQL work together to create dynamic content for your readers. A bookmarking system includes adding the current page to the MySQL table and retrieving the user's bookmark when he returns to the Web page. The system helps your users save files, pages and settings.

Instructions

    • 1

      Right-click the PHP page you want to use to store the bookmark. Click "Open With" and select your preferred PHP page.

    • 2

      Add the following database connection string to the top of the file, replacing the "user," "password" and "database" with your own connection values:

      mysql_connect("localhost", "user", "password") or die(mysql_error());
      mysql_select_db("database") or die(mysql_error());

    • 3

      Add the function to store the page in the database. You can store the data with the user who clicked the button or just store the page, if you want to make the bookmark public. The following code inserts the bookmark into the database:

      mysql_query("INSERT INTO bookmarks (page, user) VALUES('mypage.html', '23' ) ")

    • 4

      Create a button used to indicate to the user that he click it to store the page as a bookmark. Add the following code in the HTML section of the PHP page:

      <input type="button" value="Create Bookmark">

    • 5

      Open the PHP page you want to use to view the bookmarks, replacing "theuser" with the user name associated with the bookmark. The following code retrieves the bookmark you created from the table:

      $bookmarks = mysql_query("SELECT * FROM bookmarks where user='theuser'")

    • 6

      Display the bookmarks in the user's browser with the following code:

      echo "Your bookmark: ".$bookmarks[0];

Related Searches:

References

Comments

Related Ads

Featured