Jump to content

Recommended Posts

I'm looking for a simple bookmarking system. Just something that wil accept a name and a url, nothing fancy. I've searched all over and can't find anything simple.

 

Or, anyone have a clue how I would code one? I no very little php.

 

All I need is something that will take a name and url from a form and post it to a page in a list. Maybe a delete function just in case I wanted to delete one but that's about it.

 

Anyone have any input?

Link to comment
https://forums.phpfreaks.com/topic/79333-solved-php-bookmarking-system/
Share on other sites

Have you even attempted to code it? This forum is not for people to code things for you, it is for specific help with problems that occur with peoples already existing code.

 

I suggest to go through some online tutorials, or if you not interested in learning PHP/MySQL, then hire a freelancer.

 

www.tizag.com

or

www.w3schools.com

are good places to start.

maybe a this

http://www.freewebmasterhelp.com/tutorials/phpmysql

after a quick review it seams perfect for what you want :) (maybe)

 

sorry to "pass the buck" but were here to help.. if you want us to write the code for you.. your need to post in freelance section and offer something..

 

Doing it via a database would be easier.

 

I'd do it like this -

 

The form to write to the database(bookmarks.php):

<?php
include('config.php');

switch($_GET['do'])
{
  default:
   echo ' 
   <form method="?do=write" method="post">
   Your name: <input type="text" name="name" /><br />
   URL: <input type="text" name="url" /><br />
   <input type="submit" value="Submit" />
   </form>
   ';
  break;

  case 'write':
    $name = mysql_escape_string(htmlspecialchars($_POST['name'])); // Get the value of "name" from the form.
    $url = mysql_escape_string(htmlspecialchars($_POST['url'])); // Get the value of "url" from the form.


    function submitForm($name, $url)
    {
      // Insert the data into the database.
      $sql = mysql_query(sprintf("INSERT INTO `bookmarks` ( `name`, `url` ) VALUES ( '%s', '%s' )", $name, $url)) or die('Error: ' . mysql_error());

      if($sql)
      {
        echo 'Your bookmark has been submitted successfully. View a list <a href="view.php">Here</a>';
      }
      else
      {
        echo 'There appears to be an error. Please <a href="bookmarks.php">go back</a> and try again.';
      }
    }

    function checkValues($name, $url) // Check form for valid inputs
    {
      $input = false;
      foreach($_POST as $field)
      {
        if($field == '')
        {
          $input = false;
        }
        else
        {
          $input = true;
        }
      }

      if($input)
      {
        submitForm($name, $url);
      }
      else
      {
        echo 'There appears to be an error. Please <a href="bookmarks.php">go back</a> and try again.';
      }
    }
    
    checkValues($name, $url);
  break;
}
?>

 

The view.php page:

 

<?php 
include('config.php');

$sql = mysql_query(sprintf("SELECT * FROM `bookmarks`")) or die('Error: ' . mysql_error());

while($row = mysql_fetch_array($sql))
{
  echo '
  <table cellpadding="0" cellspacing="0">
  <tr>
  <td style="padding-top: 10px;">Name:</td>
  <td>' . $row['name'] . '</td>
  </tr>
  <tr>
  <td>URL:</td>
  <td>' . $row['url'] . '</td>
  </tr>
  </table>
  ';
}
?>

 

config.php:

 

<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'website';

$con = mysql_connect($host, $user, $pass);

if($con)
{
  mysql_select_db($db);
}
else
{
  die('Could not connect to database');
}
?>

 

I'm not sure if thats what you're looking for or even if this works since i just literally wrote it without testing it.

 

 

 

 

 

 

 

 

Some how I managed to hack this out. Took a combo of the tutorials mentioned above and a couple others.

 

Take a look: http://www.racinnation.com/sandbox/bookmark/form.php

 

It's very crude but it's something to build on.

 

How can I make the url output in my http://www.racinnation.com/sandbox/bookmark/bookmarks.php file linkable and to open in a new window?

 

BTW: Thanks for the quick responses.

I've been playing around and somehow get an error.

 

Parse error: parse error, unexpected '}' in /homepages/27/d192713422/htdocs/sandbox/bookmark/insert.php on line 11

 

in my insert file, code:

 

<?php $host="db1250.perfora.net"; // Host name $username="dbo226106710"; // Mysql username $password="8pf375hX"; // Mysql password $db_name="db226106710"; // Database name $tbl_name="bookmarks"; // Table name // Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form $name=$_POST['name'];
$url=$_POST['url'];
// Insert data into mysql $sql="INSERT INTO $tbl_name(name, url)VALUES('$name', '$url')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful". if($result){
echo "Successful";
echo "<BR>";
echo "<a href='form.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
// close connection mysql_close();
?>

 

any ideas what could be wrong?

Using:

 

// Get values from form $name=$_POST['name'];
$url=$_POST['url'];
// Insert data into mysql $sql="INSERT INTO $tbl_name(name, url)VALUES('$name', '$url')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful". if($result){
if ($result) {
echo "Successful";
echo "<BR>";
echo "<a href='form.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
// close connection mysql_close();
?>

 

I get "cannot connect"???

Using:

 

// Get values from form $name=$_POST['name'];
$url=$_POST['url'];
// Insert data into mysql $sql="INSERT INTO $tbl_name(name, url)VALUES('$name', '$url')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful". if($result){
if ($result) {
echo "Successful";
echo "<BR>";
echo "<a href='form.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
// close connection mysql_close();
?>

 

I get "cannot connect"???

 

In this code (above) you don't have a mysql_connect nor mysql_select_db functions... Could be why, perhaps?

Got it, used:

 

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("db226106710", $con);$sql="INSERT INTO bookmarks (name, url)
VALUES
('$_POST[name]','$_POST[url]')";if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";mysql_close($con)
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.