我想做以下事情。我输入值并单击提交。如果该值超出范围 0 和 299,则将文本 'blabla' 保存到变量 $error 中。如果在 0 到 299 的范围内更新值到 MySQL 表中(行 - SkinID);这是我尝试过但没有奏效的方法。这是我的 HTML 表单:
<form action="skinid.php" method="POST">
<!--<fieldset class="textarea-field">
<textarea title="Message">Message</textarea>
</fieldset>-->
<br>
<fieldset>
<span class="ico user-ico"></span>
<input name="skinid" onkeypress="return isNumberKey(event)" type="text" class="field" value="Enter new Skin ID. (-2000$)" title="Enter new Skin ID. (-2000$)" />
</fieldset>
<center><input type="submit" class="submit btn blue-btn" value="Update" /></center>
</form>
<?php $_SESSION['skinid'] = $_POST['skinid']; ?>
这是 skinid.php 文件:
<?php
session_start();
$newskinid = $_SESSION['skinid'];
if($newskinid < '0' || $newskinid > '299'){$error = 'The Skin ID must be in the range of 0 and 299.';}
else {
$con=mysqli_connect("localhost","USERNAME","PASSWORD","DB-NAME");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"UPDATE users SET SkinID=$newskinid
WHERE Username='$_SESSION[user]'");
mysqli_close($con);}
?>