gpt4 book ai didi

PHP 书签

转载 作者:行者123 更新时间:2023-11-29 14:34:47 28 4
gpt4 key购买 nike

我正在尝试创建一个在线书签系统。我已经设法从用户​​那里获取 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;
}

最佳答案

您必须向表中添加更多列,但这是如何实现的:

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

}

关于PHP 书签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9295856/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com