0
有人可以幫助我,我想創建一個用戶喜歡的系統。用戶應該能夠像按鈕一樣點擊A,並讓它插入該配置文件的user_id並自動增加喜歡列。我還試圖讓下一個出現並喜歡同一個配置文件的人也可以像每次更新喜歡自動增量列一樣。通過+1更新mysql中的自動增量列?
我是新來的MySQL和PHP,我真的很努力與此。有人能告訴我我哪裏出錯了嗎?提前致謝。
<?php
require_once('includes/session.php');
require_once('includes/functions.php');
require('includes/_config/connection.php');
session_start();
confirm_logged_in();
if (isset ($_GET['to'])) {
$user_to_id = $_GET['to'];
}
if (!isset($_GET['to']))
exit('No user specified.');
$user_id = $_GET['to'];
$result = mysql_query("SELECT * FROM ptb_likes WHERE liked_id ='".$user_to_id."' ");
if(mysql_num_rows($result) > 0) {
mysql_query("UPDATE ptb_likes SET likes +1 WHERE liked_id = '".$user_to_id."' ");
$autoinc = mysql_query("ALTER TABLE likes AUTO_INCREMENT = $id");
}
else
{
mysql_query("INSERT INTO ptb_likes (liked_id) VALUES ('".$user_to_id."') ");
}
if($result)
{
header("Location: {$_SERVER['HTTP_REFERER']}");
}
?>