UPDATE schijnt niks te doen
Tabel ziet er als volgt uit:
id
guild
status
Code:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
$sql = "SELECT * FROM members WHERE `username` = '$username' LIMIT 1";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($query);
$sql_app = "SELECT realname, COUNT(id) FROM application WHERE done='no'";
$query_app = mysql_query($sql_app) or die(mysql_error());
$show = mysql_fetch_assoc($query_app);
$admincheck = $row["rank"];
if($admincheck == admin)
{
?>
<?php include("includes/functions.php"); ?>
<?php
//////////////////////////////////////////
////// ENTER ALL YOUR CODE BELOW /////////
//////////////////////////////////////////
?>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<?php
if(isset($_POST['update'])) {
$sqls = ("UPDATE political SET `status` ='$status' WHERE `guild` ='$guild'");
$result = mysql_query($sqls) or die (mysql_error());
echo "Guild status has been changed";
}
$sql = mysql_query("SELECT * FROM political") or die(mysql_error());
while($row = mysql_fetch_assoc($sql)) {
$id = $sql['id'];
?>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="268"><input type="hidden" name="guild" value="<?php echo $row['guild']; ?>" /><?php echo $row['guild']; ?></td>
<td width="243"><select name="status" id="select">
<option value="<?php echo $row['status']; ?>"><?php echo $row['status']; ?></option>
<option value=" "></option>
<option value="Allied">Allied</option>
<option value="Neutral">Neutral</option>
<option value="Enemy">Enemy</option>
</select>
</td>
<td width="89"><input type="submit" name="delete" id="button" value="Delete!" /></td>
</tr>
<br />
<?php
}
?>
</table>
<bR />
<br />
<center>
<input type="submit" name="update" value="Update!" />
</center>
</form>
$sql = "SELECT * FROM members WHERE `username` = '$username' LIMIT 1";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($query);
$sql_app = "SELECT realname, COUNT(id) FROM application WHERE done='no'";
$query_app = mysql_query($sql_app) or die(mysql_error());
$show = mysql_fetch_assoc($query_app);
$admincheck = $row["rank"];
if($admincheck == admin)
{
?>
<?php include("includes/functions.php"); ?>
<?php
//////////////////////////////////////////
////// ENTER ALL YOUR CODE BELOW /////////
//////////////////////////////////////////
?>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<?php
if(isset($_POST['update'])) {
$sqls = ("UPDATE political SET `status` ='$status' WHERE `guild` ='$guild'");
$result = mysql_query($sqls) or die (mysql_error());
echo "Guild status has been changed";
}
$sql = mysql_query("SELECT * FROM political") or die(mysql_error());
while($row = mysql_fetch_assoc($sql)) {
$id = $sql['id'];
?>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="268"><input type="hidden" name="guild" value="<?php echo $row['guild']; ?>" /><?php echo $row['guild']; ?></td>
<td width="243"><select name="status" id="select">
<option value="<?php echo $row['status']; ?>"><?php echo $row['status']; ?></option>
<option value=" "></option>
<option value="Allied">Allied</option>
<option value="Neutral">Neutral</option>
<option value="Enemy">Enemy</option>
</select>
</td>
<td width="89"><input type="submit" name="delete" id="button" value="Delete!" /></td>
</tr>
<br />
<?php
}
?>
</table>
<bR />
<br />
<center>
<input type="submit" name="update" value="Update!" />
</center>
</form>
Misschien dat ik ergens zomaar overheen lees, maar hij wilt niet de waarden updaten die ik in de input select verander.
waar word $status en $guild gedeclareerd? ;)
maak daar even $_POST['status'] en $_POST['guild'] van..
Gewijzigd op 01/01/1970 01:00:00 door - -
Misschien domme vraag, maar worden die niet direct uit de name tags gehaald ?
Ik heb nu de twee waarden gedeclareerd, maar nog schijnt het niet te werken.
Echo je query, je ziet snel genoeg waar het mis gaat.
Deze query is fout en zou een dikke foutmelding moeten opleveren. Maar ja, MySQL....
Er mist een GROUP BY in de query, deze is verplicht zodra je behalve een aggregate functie (COUNT in dit geval) ook andere kolommen gaat opvragen. Al deze kolommen MOET je in de GROUP BY vermelden. In dit geval wordt het dan:
Tip: Ga de database configureren, dat scheelt je een hoop overbodig werk. Fouten komen dan sneller aan het licht.