This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-06-30 05:58:09

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

<select> surprise in POST... please explain!

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:

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:

Code:

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)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2011-06-30 16:48:10

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: <select> surprise in POST... please explain!

I originally posted this in misc but nothing happened so I will try advanced  tongue

Last edited by sparks (2011-06-30 16:48:41)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#3 2011-06-30 18:52:43

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: <select> surprise in POST... please explain!

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)


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#4 2011-06-30 21:10:51

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: <select> surprise in POST... please explain!

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?


I am currently http://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=imagehttp://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=text and I finally got over 1000 posts.

Offline

 

#5 2011-07-01 03:27:33

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: <select> surprise in POST... please explain!

Maybe your database field 'extraStatus' is not equalling ''.

Based on the code, try this.

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)){
                    $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.


You can now reach me on Twitter @johnnydean1_

Offline

 

#6 2011-07-01 06:14:25

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: <select> surprise in POST... please explain!

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!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#7 2011-07-01 10:31:48

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: <select> surprise in POST... please explain!

Well you didn't need us really  smile  But I s'pose we got your brain working


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#8 2011-07-01 10:55:19

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: <select> surprise in POST... please explain!

It was when I read over jd's example  tongue  I thought it was something he'd changed but it wasn't!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

Board footer