Hey guys,
I've been working on a cpanal for my site today, there is a dropdown list of registered members with the following code:
<form name = account search' method = 'post' action = '10807411.php?page=accountFinder'>
<select name = 'searchType'>";
mysql_connect("localhost", "******", "******") or die(mysql_error());
mysql_select_db("********_members") or die(mysql_error());
$query = "SELECT * FROM membersList ORDER BY id ASC";
mysql_query($query);
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
if($row['extraStatus'] == ''){
if($row['status'] == 'registered'){
$status = '[R]';
}
if($row['status'] == 'blocked'){
$status = '[b]';
}
}
else{
if($row['extraStatus'] == 'moderator'){
$status = '[M]';
}
else{
$status = '[?]';
}
}
echo "<option value = '" . $row['username'] . "'>" . $status . $row['username'] . "</option>";
}
echo "</select>
<input type = 'submit' name = 'searchUser' value = 'GO'>
</form>";Now if you look there you will see that all the members of my site are pulled from the database and stored for selection in a dropdown list with a [ ] preceding each one indicating status.
so for example with the above code an entry would look like so:
[M]sparks
So surely when the form is posted, the value of $_POST['searchType'] should really be '[M]sparks when this code is used on the next page:
echo "<h2>" . $_POST['searchType'] . "s Account.</h2>";
However, this ends up displaying sparkss account.... the [M] has disappeared!
This is actually exactly what I wanted as the [M] was going to get in the way, but I'm wondering where on earth it went?! are things inside square brackets ignored when they are inside select inputs for forms?
Last edited by sparks (2011-06-30 16:47:41)
Offline
your code seems to be correct (although I may be wrong) but I think it's probably your database.
Edit:
I think it's because
$row['extraStatus'] == ''
but
$row['status'] != registered
and/or
$row['status'] != 'blocked'
I may be wrong though
Last edited by RUMCHEERYPOOPOO (2011-06-30 18:55:39)
Offline
I think that it is some thing with the brackets ( [ ] ) because, for some reason, the database deletes that part. maybe it's a comment or something?
Offline
Maybe your database field 'extraStatus' is not equalling ''.
Based on the code, try this.
<form name = account search' method = 'post' action = '10807411.php?page=accountFinder'>
<select name = 'searchType'>";
mysql_connect("localhost", "******", "******") or die(mysql_error());
mysql_select_db("********_members") or die(mysql_error());
$query = "SELECT * FROM membersList ORDER BY id ASC";
mysql_query($query);
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$status = '[u]';
if($row['extraStatus'] == ''){
if($row['status'] == 'registered'){
$status = '[R]';
}
if($row['status'] == 'blocked'){
$status = '[b]';
}
}
else{
if($row['extraStatus'] == 'moderator'){
$status = '[M]';
}
else{
$status = '[?]';
}
}
echo "<option value = '" . $row['username'] . "'>" . $status . $row['username'] . "</option>";
}
echo "</select>
<input type = 'submit' name = 'searchUser' value = 'GO'>
</form>";If it says [u]Sparkss then you know its wrong for the above reason.
Offline
Good idea, but the fact is that in the DROPDOWN of all the members the [m] does appear! So it has managed to set the status to [M] and ...
OH! It's because <option> name is $status . $row['username'] whilst the value is only set to $row['username']! Tha value is carried through the POST to the next page! How silly of me!
Offline
Well you didn't need us really
But I s'pose we got your brain working
Offline