Reputation: 1
I am trying to create an online bookmark system. I have managed to take the URL from the user and store it to the database. But I want also to take "Title and tags" can anyone help me with the code..
function add_bm($new_url)
{
// Add new bookmark to the database
echo "Attempting to add ".htmlspecialchars($new_url).'<br />';
$valid_user = $_SESSION['valid_user'];
$conn = db_connect();
// check not a repeat bookmark
$result = $conn->query("select * from bookmark
where username='$valid_user'
and bm_URL='$new_url'");
if ($result && ($result->num_rows>0))
throw new Exception('Bookmark already exists.');
// insert the new bookmark
if (!$conn->query( "insert into bookmark values
('$valid_user', '$new_url')"))
throw new Exception('Bookmark could not be inserted.');
return true;
}
Upvotes: 0
Views: 382
Reputation: 17895
You will have to add more columns to your table but hows this:
// Add new bookmark to the database
function add_bm($new_url, $new_title, $new_tags){
echo "Attempting to add ".htmlspecialchars($new_url).'<br />';
$valid_user = $_SESSION['valid_user'];
$conn = db_connect();
// check not a repeat bookmark
$result = $conn->query("select * from bookmark where username='$valid_user' and bm_URL='$new_url'");
if ($result && ($result->num_rows>0)){
throw new Exception('Bookmark already exists.');
}
// insert the new bookmark
if (!$conn->query("insert into bookmark values('$valid_user', '$new_url', '$new_title', '$new_tags')")){
throw new Exception('Bookmark could not be inserted.');
}
return true;
}
Upvotes: 1