【发布时间】:2013-07-24 12:58:22
【问题描述】:
我的 php mysql-code 很奇怪。
这有时会起作用,有时当我执行这行代码时它会将所有值设置为 0。
$tid = htmlentities(mysql_real_escape_string($_POST['themes']));
$sql = ("UPDATE ai_themes
SET chosen = IF(tid!='$tid', '0','1')");
mysql_query($sql);
有时一夜之间所有的值都是 0。 还没有看过枚举类型,只是好奇为什么会这样......
主题表:
tid = int, PK, NOT NULL, AUTO_INCREMENT
name = varchar(30)
chosen = tinyint(1)
[编辑]
嗯,我似乎没有从选择表单中获得有效值:
<form action="my_form_handler.php?c=3" method="post" data-transition="slideup">
<div data-role="fieldcontain">
<label for="themes" class="select">Select theme:</label>
<select name="themes" id="select-theme">
<option value="1">Red</option>
<option value="2">Green</option>
<option value="3">Orange</option>
<option value="4">Blue</option>
</select>
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<button type="submit" data-theme="a" name="submit" value="submit-value">Change theme</button>
</div>
</form>
看不到任何错误...
【问题讨论】:
-
htmlentities - 那里需要吗? & $_POST['themes'] 中的值是多少;
-
不,但是,一个人永远不能太贪吃......
标签: php mysql enums sql-update