2012-02-15 73 views
0

我想創建一個在線書籤系統。 我設法從用戶​​處獲取URL並將其存儲到數據庫中。但我想也採取「標題和標籤」 誰能幫助我的代碼..php書籤

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; 
} 

回答

1

你將有更多的列添加到您的表,但是怎麼樣了這一點:

// 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; 

}