插入代码不会插入php

时间:2012-11-15 22:25:08

标签: php

我有一个类似戳的应用程序,它似乎没有插入表'戳'。

尽管我的代码看起来很好看,它似乎没有显示出任何迹象? 有什么想法吗?

if (@$_POST['poke']) {
  $check_if_poked = mysql_query("SELECT * FROM pokes WHERE user_to='$username' AND user_from='$added_by'");
$num_poke_found = mysql_num_rows($check_if_poked);
if ($num_poke_found == 1) {
 echo "Come on! Give the guy a chance!";
  }
 else
 if ($username == $cookie) {
 echo "You cannot Jab yourself.";
 }
 else
  { $poke_user = mysql_query("INSERT INTO pokes VALUES ('', '$cookie', '$username')") or trigger_error(mysql_error());
 echo "$username has been jabbed.";
  }

}

1 个答案:

答案 0 :(得分:1)

在MySQL中,您可以使用AND而不是&&

SELECT * FROM pokes WHERE user_to='$username' AND user_from='$added_by'

对于插入,您需要指定要添加的列

INSERT INTO pokes (ColumnA, ColumnB) VALUES ('A', 'B')

要进一步调试,请尝试checking for errors ...

$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {
    die('Invalid query: ' . mysql_error());
}