我有几个选择语句看起来像这样.我需要将php变量传递到我的数据库中.
<select name="gamestart" >
<?php for($gamestart=1; $gamestart<=24; $gamestart++)
echo "<option value='$gamestart'>$gamestart:00</option>";
?>
</select>
Run Code Online (Sandbox Code Playgroud)
这是我的插入语句到我的数据库与其他类似的变量,我有同样的问题.
<?php
$mysql_query = "INSERT INTO soccer_games (gamestart, gameend)
VALUES ('$gamestart', '$gameend')";
$this->db->query($mysql_query);
?>
Run Code Online (Sandbox Code Playgroud)
截至目前,值已被放入数据库,但INSERT进入数据库的值是数字25(在我的循环中甚至不是一个选项,你可以看到),无论我在表单中选择什么值.
编辑1:问题可能是我没有使用过表格(我的无限智慧中的我没有意识到我需要一个表格).
我假设我需要这种性质的东西......
public function insertstatements(){
<?php
$mysql_query = "INSERT INTO soccer_games (gamestart, gameend)
VALUES ('$gamestart', '$gameend')";
$this->db->query($mysql_query);
?>
}
<form method="post" action="<?php insertstatements(); ?>">
<select name="gamestart" >
<?php for($gamestart=1; $gamestart<=24; $gamestart++)
echo "<option value='$gamestart'>$gamestart:00</option>";
?>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)