因此,当我在表单上输入信息后,它会使用新表单刷新 new.php 页面,但不会提交任何信息。我没有收到任何错误,就像我在页面上单击刷新一样。我觉得我已经做对了一切,但我似乎无法弄清楚为什么这不起作用。我刚刚从 mysql 过渡到 mysqli,所以我对它有点菜鸟。它也不会路由回 home.php。
new.php
<?php include_once('header.php'); ?>
<?php include_once('config/db.php'); ?>
<div id="newform">
<form role="form">
<div class="form-group">
<label for="user">User</label>
<input type="text" class="form-control" id="user" placeholder="Username">
</div>
<div class="form-group">
<label for="rank">Rank</label>
<select class="form-control" name="rank">
<option value="1">Noob</option>
<option value="2">Semi-Noob</option>
</select>
</div>
<div class="form-group">
<label for="date">Date</label>
<input type="text" class="form-control" id="date" placeholder="<?php echo date('d M y'); ?>">
</div>
<div class="form-group">
<label for="tag">Tag</label>
<input type="text" class="form-control" id="tag" placeholder="Tag">
</div>
<center>
<button type="submit" class="btn btn-default">Submit</button>
</center>
</form>
</div>
<?php
if(isset($_POST['submit'])){
//Values to be inserted into the DB
$user = $_POST['user'];
$rank = $_POST['rank'];
$date = $_POST['date'];
$tag = $_POST['tag'];
//Preparing the statement
$query = "INSERT INTO players (user, rank, date, tag) VALUES(?, ?, ?)";
$statement = $mysqli->prepare($query);
//Binding Parameters for markers, where (s = string, i = integer, d = double, b = blob)
$statement->bind_param('siss', $user, $rank, $date, $tag);
//Execution
if($statement->execute()){
header('Location: home.php');
}else{
die('Error : ('.$mysqli->errno .') '. $mysqli->error);
}
$statement->close();
}
?>
<?php include_once('footer.php'); ?>
添加后查看name="submit"
in <button type="submit" class="btn btn-default">Submit</button>
<button type="submit" class="btn btn-default" name="submit">Submit</button>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)