简体   繁体   English

这种MySQL语法很糟糕,有时可以工作,有时却不能……(严重)

[英]This MySQL syntax is honky, sometimes it works and sometimes it doesnt… (seriously)

Check this out: 看一下这个:

if (isset($_POST['username'])) { 
    $username = $_POST['username'];
}

$connect = mysql_connect("localhost", "root", "");
mysql_select_db("TagDB");

$query = mysql_query("UPDATE friendtable SET state = '1' 
    WHERE (userB = '$username' AND state = '0')");

This should simply update a table to show a state of 1 for every instance the userB column consists of the posted username. 对于userB列由发布的用户名组成的每个实例,这应该只更新一个表以将状态显示为1。 However, this only works sometimes. 但是,这有时仅适用。 Without changing any code whatsoever, this method will sometimes to as it ought to, and other times do nothing. 在不更改任何代码的情况下,此方法有时会达到应有的效果,而其他时候则什么也不做。 Strange. 奇怪。

if (isset($_POST['state'])) {
    $state = $_POST['state'];
}

if (isset($_POST['username'])) {
    $username = $_POST['username'];
}

if (isset($_POST['frienduser'])) {
    $frienduser = $_POST['frienduser'];
}

$connect = mysql_connect("localhost", "root", "");
mysql_select_db("TagDB");

$query = mysql_query("UPDATE friendtable SET state = '$state' WHERE (userA = '$frienduser' AND userB = '$username')");

This does the same. 这也一样。 Sometimes its perfect, other times, no change. 有时它是完美的,其他时候则没有变化。 I have no idea what could be different. 我不知道会有什么不同。 My only lead is that I sometimes manually change values in MySQL via phpmyadmin to test some stuff. 我唯一的线索是,有时我会通过phpmyadmin手动更改MySQL中的值以测试某些内容。 Could it be getting confused because I'm putting in some values manually? 会因为我手动输入一些值而感到困惑吗? I wouldn't think so, but its the only lead I have. 我不这么认为,但这是我唯一的领先优势。 Take a look at the code and see if you can spot anything that would cause this strange issue, if you have the time. 如果有时间,请看一下代码,看看是否可以发现任何可能导致此奇怪问题的内容。 Thank you. 谢谢。

I'm a complete idiot. 我是个白痴。 I'm posting this as an answer to help anyone who may run into this problem too. 我将其发布为答案,以帮助可能也会遇到此问题的任何人。 Basically, I would change the state to 0 to check if various inputs worked. 基本上,我会将状态更改为0,以检查各种输入是否有效。 I'd then refresh the page to see if the state had changed after I had made an input. 然后,我将刷新页面以查看输入后状态是否已更改。 However, when refreshing the page it refreshed my previous mysql request.... to set the state to 0. So by refreshing I was really undoing what I had just done. 但是,在刷新页面时,它刷新了我之前的mysql请求....,将状态设置为0。因此,通过刷新,我实际上是在撤消刚刚做的事情。 Sorry to bother you all with this, but hopefully this post will serve someone else in the future. 很抱歉打扰您,但希望这篇文章将来会为其他人服务。 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM