0
有人可以帮助我吗。我试图通过将值插入到mysql中并创建一个基本的系统,并自动递增列'喜欢'更新的次数。值没有插入到mysql并没有更新枚举值为1?
基本上脚本将插入其中,目前还没有任何记录和更新,如果有一个记录。
我试图插入“USER_ID”作为一种价值,藏汉但只有liked_id被插入到表中。在“喜欢”列正在自动递增的理所应当的,但我需要找出如何我可以插入USER_ID这是用户会话ID aswel,这是不是正在落实。另我试图更新列' user_id_has_liked'从枚举值0到1作为最终结果。
有人可以告诉我在哪里,我错了。感谢
<?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 = likes +1 WHERE liked_id = '".$user_to_id."' ");
$user_to_id = mysql_query("ALTER TABLE likes AUTO_INCREMENT = $id");
}
else
{
mysql_query("INSERT INTO ptb_likes (user_id,liked_id) VALUES ('".$_SESSION['user_id'].",".$user_to_id."') ");
}
$result1 = mysql_query("UPDATE ptb_likes SET user_id_has_liked='1' WHERE user_id=".$_SESSION['user_id']."")
or die(mysql_error());
if($result)
{
header("Location: {$_SERVER['HTTP_REFERER']}");
}
?>
[**请勿在新代码中使用'mysql_ *'函数**] (http://bit.ly/phpmsql)。他们不再被维护[并被正式弃用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**红框**](http://j.mp/Te9zIL)?学习[*准备的语句*](http://j.mp/T9hLWi),并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [这篇文章](http://j.mp/QEx8IB)将帮助你决定哪个。如果你选择PDO,[这里是一个很好的教程](http://j.mp/PoWehJ)。 – 2013-02-10 04:39:45
你会得到什么错误信息?你到目前为止做了哪些故障排除? – 2013-02-10 04:41:12
'的mysql_query( “ALTER TABLE喜欢AUTO_INCREMENT = $ ID”);'会被列为极其阴暗的代码。 – 2013-02-10 04:42:41