当我想在1行中保存2个变量时,我在插入数据库时遇到问题。
在这里,当我输入名称时,我得到了我想要的形式,并选择所有其他东西以保存我选择的项目并以指定的颜色输入以便以该颜色保存在数据库中。
<form action="" method="post">
<fieldset>
<legend> Add user </legend>
<p><label class="field" for="user">User :</label> <input type="text" name="user" id="user"></label></p>
<p><label class="field" for="roll">Points :</label>
<select name="roll_chance" id="roll">
<option value=""></option>
<option value="*">*</option>
<option value="**">**</option>
<option value="***">***</option>
</select>
</p>
<p><label class="field" for="class">Class :</label>
<select name="class" id="class">
<option value=""></option>
<option value="Assasin">Assasin</option>
<option value="Bard">Bard</option>
<option value="Mage">Mage</option>
<option value="Marksman">Marksman</option>
<option value="Protector">Protector</option>
<option value="Priest">Priest</option>
<option value="Reaper">Reaper</option>
<option value="Tormentor">Tormentor</option>
<option value="Vampire">Vampire</option>
<option value="Warrior">Warrior</option>
</select>
</p>
<p><label class="field" for="color">Color :</label>
<select name="color" id="color">
<option value=""></option>
<option value="yellow">Yellow</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
</select>
</p>
<p><input type="submit" name="submit" value="Save"></p>
</fieldset>
</form>
if (isset($_POST['submit']))
{
if (isset($_POST['user']) && isset($_POST['roll_chance']) && isset($_POST['class']) && isset($_POST['color'])) {
$user = htmlentities($_POST['user']);
$roll = htmlentities($_POST['roll_chance']);
$class = htmlentities($_POST['class']);
$color = htmlentities($_POST['color']);
$user = strip_tags($user);
$roll = strip_tags($roll);
$class = strip_tags($class);
$color = strip_tags($color);
$stmt = $dbh->prepare ("INSERT INTO users (user, roll_chance, class) VALUES (:user, :roll, :class)");
$stmt->bindParam(':user', '<span style"color:'.$color.';">'.$user.'</span>');
$stmt->bindParam(':roll', $roll);
$stmt->bindParam(':class', '<span style"color:'.$color.';">'.$class.'</span>');
$stmt->execute();
}
}
答案 0 :(得分:0)
我建议拆分数据和布局,并在表格中创建一个名为df4 <- structure(list(hour = c(0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 0L),
cs = c(0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L),
cs_acum = c(0L, 0L, 0L, 0L, 0L, 1L, 2L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 0L, 0L),
cs_wanted = c(0L, 0L, 0L, 0L, 0L, 1L, 2L, 3L, 0L, 0L, 4L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 0L, 0L),
cs_acum2 = c(0L, 0L, 0L, 0L, 0L, 1L, 2L, 3L, 0L, 0L, 4L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 3L, 0L, 4L, 5L, 0L, 0L)),
.Names = c("hour", "cs", "cs_acum", "cs_wanted", "cs_acum2"), class = "data.frame", row.names = c(NA, -36L))
的列。并更改查询,如:
SETTINGS
稍后在输出中使用此color
值。
如果以后您需要将布局从$stmt = $dbh->prepare ("INSERT INTO users (user, roll_chance, class, color) VALUES (:user, :roll, :class, :color)");
$stmt->bindParam(':user', $user);
$stmt->bindParam(':roll', $roll);
$stmt->bindParam(':class', $class);
// insert color
$stmt->bindParam(':color', $color);
$stmt->execute();
更改为color
或其他标记,这将使您的生活更轻松。