我正在尝试创建在线书签系统。 我已设法从用户获取URL并将其存储到数据库。但我也想采取“标题和标签” 任何人都可以帮我代码..
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;
}
答案 0 :(得分: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;
}