Customizing SMF > SMF Coding Discussion

database select box problem

(1/3) > >>

The Wizard:
Objective:

To read the column "wizard" and return the results in a select box that the user can then choose what image they want to remove form the column "wizard".

I'm not sure if this code will work or not so if you see any problems please help. I'm still learning PHP.

Wiz




--- Code: ---<?php

// Wizard Image Removal Page


global $smcFunc, $db_prefix, $user_info;
 
// Get the user's information from the database

      $result = $smcFunc['db_query']('', "
      SELECT wizard
     FROM {db_prefix}members
     WHERE id_member = {int:current_member}
     LIMIT 1",
     array(
       'current_member' => $user_info['id'],
   ));

 // Create a Dropdown box and select Image name to remove form Database    
        if($result) {
   
            echo'<form id="form1" name="form1" method="post" action="">
                 <select name="user" id="user">
                 <option value="0" selected="selected">Select Image to Remove</option>';

            $i=0;

while ($row = $smcFunc['db_fetch_assoc']($result)) {
                                    
echo '<option value='.$i.'>'.$row.'</option>';
            
$i++;   
                }  
            }
            echo'</select></form>';

// Save all the orginal image names Except the image name that was removed

     updateMemberData($user_info['id'], array('wizard' => $row));


?>

--- End code ---

The Wizard:
Ok I tryed this code out myself and got this error any ideas how to fix it?


--- Quote ---Fatal error: Function name must be a string in Sources/shop/image_remove2.php on line 9

--- End quote ---

Kays:
There's a couple of a problems with what you you posted above.

First of, wizard is a comma separated value. So you can't use that until it's exploded back into an array. Then loop though that to display the individual items.

Secondly, that's not how a form works. It's actually a two part thing. First there's the forum where the data is altered by the user. Then when it get's submitted the user get's taken to a second page which is defined by the "action" set in the forum which does the actual processing. and then the user gets taken back to the original page. It can also be done using the same page but it still needs to be accessed multiple times. Also when you do this the data gets passed using the $_POST variable and that's what needs to be processed.

So, take a look online for a tutorial on how to create a form and how to handle the data from it. Create  dummy page include SSI.php and try to build a form on that using the tutorial as a guide before you go messing with the SMF code. It's a bit more complex than you think.

Where were you going to place this form? If it's somewhere in the user's profile, then you can use an existing forum rather than adding a separate one. But either way, you need to understand how a form works first.

The Wizard:
Your right as always Kays. I wanted to short cut the Right way to do it and I should have known better. I'll review how to create a form again and do it the right way. As always thanks for the words of wisdom.

Wiz

Kays:
Nope, there ain't no short cut and there's only a very limited number of ways it can or should be be done. :)

Do create a separate page on which to do this just to play around with and to get comfortable on how to do things. In thinking abut this you don't even need the query. If this is for the user to alter "his(or her)" wizard image then that should be available in the user's profile already. ($user_info, I think.)

Navigation

[0] Message Index

[#] Next page

Go to full version