首先,我对 PHP 和数据库完全陌生。我有一个关于创建网站的问题,我在其中创建了一个用户可以登录并与之交互的数据库。更具体地说,我创建了一个音乐商店网站,用户可以登录,然后他们选择自己喜欢的磁盘,并使用同名按钮将它们添加到“收藏夹列表”中。到目前为止,在我的代码下方,仅用于收藏夹部分
<table>
<tr>
<td>
<div class="container" style="height:150px; width: 250px;">
<img src="images\ironmaiden2.jpg" style="height:160px; width:250px;" >
<div class="middle">
<div class="text2" id="1"><a href="https://www.youtube.com/watch?v=FhBnW7bZHEE" target="_blank" style="color:white;">The Writing and the Wall</a></div>
</div>
</div>
<h4><a href="ironmaiden.html">iron Maiden</a></h4>
<form name="favorite" action="favorite.php" method="post">
<input type="submit" name="submit" value="Add to Favorites">
</form>
</td>
接下来是我的 PHP 部分代码,
<?php
//header("Location: login.php");
require_once 'credent.php';
$connecionstr="host=".DB_SERVER." port=5432 dbname=".DB_BASE."
user=".DB_USER." password=".DB_PASS." options='--client_encoding=UTF8'";
$dbconn = pg_connect($connecionstr);
if (!$dbconn) {
die("Connection failed: " . pg_connect_error());
}
if(isset($_POST["submit"]))
{
if(isset($_POST['favorite'])){
$favorite=$_POST['favorite'];
$sql=pg_query("insert into favorite(id) values('$favorite')");
}
}
pg_close($dbconn);
?>
我的问题是我找不到附加/关联登录用户输入的方法 到数据库。我必须创建一个通信渠道,将已登录的用户与他在网站中所做的操作连接起来,并存储在我的数据库中。我错过了什么???