PHP代码
session_start();
ob_start();
require_once '../' . 'dbconnect.php';
$isOwner = $_POST['isOwner'];
$isAdmin = $_POST['isAdmin'];
$isJrAdmin = $_POST['isJrAdmin'];
$isMod = $_POST['isMod'];
$isJrMod = $_POST['isJrMod'];
$isManager = $_POST['isManager'];
$isBuilder = $_POST['isBuilder'];
$isDeveloper = $_POST['isDeveloper'];
$isGFX = $_POST['isGFX'];
$isPartner = $_POST['isPartner'];
$isFamous = $_POST['isFamous'];
$username = $_POST['username'];
$confirmedMSG = "<div class='alert alert-success'><span class='glyphicon glyphicon-ok'></span> User settings - Set</div>";
$usererror = false;
$selecterror = false;
$confirmed = false;
if(isset($_POST['btn-confirm'])) {
if(!empty($username)){
foreach ($isOwner as $select)
{
mysql_query("UPDATE legacycl_users SET isOwner='$select' WHERE userName='$username'");
}
foreach ($isAdmin as $select)
{
mysql_query("UPDATE legacycl_users SET isAdmin='$select' WHERE userName='$username'");
}
foreach ($isJrAdmin as $select)
{
mysql_query("UPDATE legacycl_users SET isJrAdmin='$select' WHERE userName='$username'");
}
foreach ($isMod as $select)
{
mysql_query("UPDATE legacycl_users SET isMod='$select' WHERE userName='$username'");
}
foreach ($isJrMod as $select)
{
mysql_query("UPDATE legacycl_users SET isJrMod='$select' WHERE userName='$username'");
}
foreach ($isManager as $select)
{
mysql_query("UPDATE legacycl_users SET isManager='$select' WHERE userName='$username'");
}
foreach ($isBuilder as $select)
{
mysql_query("UPDATE legacycl_users SET isBuilder='$select' WHERE userName='$username'");
}
foreach ($isDeveloper as $select)
{
mysql_query("UPDATE legacycl_users SET isDeveloper='$select' WHERE userName='$username'");
}
foreach ($isGFX as $select)
{
mysql_query("UPDATE legacycl_users SET isGFX='$select' WHERE userName='$username'");
}
foreach ($isPartner as $select)
{
mysql_query("UPDATE legacycl_users SET isPartner='$select' WHERE userName='$username'");
}
foreach ($isFamous as $select)
{
mysql_query("UPDATE legacycl_users SET isFamous='$select' WHERE userName='$username'");
}
$confirmed=true;
}else{
$usererror=true;
$errorMSG = "<div class='alert alert-danger'><span class='glyphicon glyphicon-remove'></span>Insert username</div>";
}
}
HTML代码
<section id="main">
<div class="container">
<center>Admin Control Panel
<br>
<br>
<div class="col-lg-12">
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<div class="username">
<input type="text" name="username" autocomplete="off" spellcheck="false" placeholder="Insert username...">
<div class="result"></div>
</div>
<br>
<br>
<div class="col-lg-6">
<h2>Is User Owner?</h2><br>
<select name="isOwner[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
<h2>Is User Admin?</h2><br>
<select name="isAdmin[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
<h2>Is User JrAdmin?</h2><br>
<select name="isJrAdmin[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
<h2>Is User Mod?</h2><br>
<select name="isMod[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
<h2>Is User JrMod?</h2><br>
<select name="isJrMod[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
<h2>Is User Manager?</h2><br>
<select name="isManager[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
</div>
<div class="col-lg-6">
<h2>Is User Developer?</h2><br>
<select name="isDeveloper[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
<h2>Is User Builder?</h2><br>
<select name="isBuilder[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
<h2>Is User GFX Artist?</h2><br>
<select name="isGFX[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
<h2>Is User Partner?</h2><br>
<select name="isPartner[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
<h2>Is User Famous?</h2><br>
<select name="isFamous[]">
<option value="Select...">Select...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<br>
</div>
<br>
<br>
<button type="submit" class="btn btn-block btn-primary" name="btn-confirm">Set Permissions</button>
</form>
这是一个相同格式的查询并且有效(PHP)
if(count($_POST)>0){
if(isset($username) && $username != $usertitle){
$query = "SELECT userName FROM legacycl_users WHERE userName='$username'";
$result = mysql_query($query);
$count = mysql_num_rows($result);
if($count!=0){
$nametaken = "<span class='glyphicon glyphicon-remove'></span>Name Taken...";
$nameerror = true;
$nametakenstatus = true;
}else{
if($userChangeDate <= date("Y-m-d")){
rename("../../profile/".$usertitle, "../../profile/".$username);
$updatedMSG = "<span class='glyphicon glyphicon-ok'></span><strong> Settings Updated!</strong> <br> <a href='/profile/$username' class='alert-link'>View changes!</a>";
$newDate = mktime(0, 0, 0, date("m") + 1, 1);
$setDate = date("Y-m-d", $newDate);
$newDateMSG = "Next Date for name change: $setDate";
mysql_query("UPDATE legacycl_users SET userName='$username' WHERE userId=".$_SESSION['user']);
mysql_query("UPDATE legacycl_users SET userChangeDate='$setDate' WHERE userId=".$_SESSION['user']);
header("Location: http://legacysitetemp.tk/profile/$username");
}else{
$nameerror=true;
}
}
}
$updated=true;
mysql_query("UPDATE legacycl_users SET userYoutube='{$youtube}' WHERE userId=".$_SESSION['user']);
mysql_query("UPDATE legacycl_users SET userFacebook='{$facebook}' WHERE userId=".$_SESSION['user']);
mysql_query("UPDATE legacycl_users SET userTwitter='{$twitter}' WHERE userId=".$_SESSION['user']);
mysql_query("UPDATE legacycl_users SET userDescription='{$about}' WHERE userId=".$_SESSION['user']);
}
忽略没有结束标记。我没有复制那些。
如果任何选项是&#34;我选择...&#34;它不会让更新过程。当我进行更改并尝试查询时,它停止更新。我做了一点测试,值回应了所选的选项。它只是不会更新数据库。
我不确定为什么它不起作用。是因为foreach函数还是什么?
我是php的新手,所以显然会有一些你不会喜欢的东西。
感谢您的帮助。