can someone please help me get this script right, i'm changing how i edit the forums in the admin cp of my forums.

When you click on the forum you want to edit, it should come up with the edit boxes, but it will only come up with a blank page.

Here is my function code:

function cp_forum_row($forum) {
echo <<< HTML
<a href="admin.php?action=edit-forums&fid=$forum[fid]">$forum[name]</a><br /><br />

and here is the code in my admin cp:

##### FORUMS #####
if($action == "forums" && $HTTP_POST_VARS['submit'] == "") {
	$query = mysql_query("SELECT * FROM $db_forum ORDER BY dorder") or die(mysql_error());
	while($forum = mysql_fetch_array($query)) {
	cp_forum_row($forum);
		}
if($action == "edit-forums" && $HTTP_POST_VARS['submit'] == "") {
	$query = mysql_query("SELECT name, description, dorder FROM $db_forum WHERE fid='$fid'") or die(mysql_error());
	while($forum = mysql_fetch_array($query)) {
	cp_forum_row($forum);
			}
		}

}
    HTML;
    }
    
    
    function cp_forum_row($forum) {
    echo <<< HTML
    <a href="admin.php?action=edit-forums&fid=$forum[fid]">$forum[name]</a><br /><br />

    Is that really your code in its entirety?

      that one is just 1 function which creates the url for the edit page

        Why does the end of the function appear before the beginning of the function?

          what do you mean, that's only the first function which gives ou the link to go edit the forum you clicked on in the admin cp.

            here's the old code for editing the forums just incase it helps

            function cp_forums_header:

            function cp_forums_header() {
            echo <<< HTML
            <b>Forums</b><br />
            Here you can edit/create/delete all the forums in your message board.<p>&nbsp;</p>
            
            <form method="post" action="admin.php?action=forums">
            <table width="100%">
            <tr>
            <td class="tabletxt2" width="10%"><b>Delete:</b></td>
            <td class="tabletxt2" width="30%"><b>Forum Name:</b></td>
            <td class="tabletxt2" width="55%"><b>Description:</b></td>
            <td class="tabletxt2" width="5%"><b>Order:</b></td>
            </tr>
            

            function cp_forums_row:

            function cp_forums_row($forum) {
            echo <<< HTML
            <tr>
            <td><input type="checkbox" name="delete$forum[fid]" value="$forum[fid]" /></td>
            <td><input type="text" name="name$forum[fid]" value="$forum[name]" size="30" style="width: 200px" /></td>
            <td><textarea cols="40" rows="3" name="description$forum[fid]" style="width: 300px; height: 50px">$forum[description]</textarea></td>
            <td><input type="text" name="dorder$forum[fid]" value="$forum[dorder]" size="2" style="width: 30px" /></td>
            </tr>
            

            function cp_forums_footer:

            function cp_forums_footer() {
            echo <<< HTML
            <tr>
            <td class="tabletxt2" colspan="3"><b>New Forum:</b></td>
            </tr>
            <tr>
            <td colspan="2"><input type="text" name="newname" size="30" style="width: 200px" /></td>
            <td><textarea cols="40" rows="3" name="newdescription" style="width: 300px; height: 50px"></textarea></td>
            <td><input type="text" name="newdorder" size="2" style="width: 30px" /></td>
            </tr>
            </table><br /><br />
            <input type="submit" name="submit" value="Modify Forums">
            </form>
            

            code in admin cp:

            ##### FORUMS #####
            if($action == "forums" && $HTTP_POST_VARS['submit'] == "") {
            	cp_forums_header();
            
            $query = mysql_query("SELECT * FROM $db_forum ORDER BY dorder") or die(mysql_error());
            while($forum = mysql_fetch_array($query)) {
            	cp_forums_row($forum);
            }
            
            cp_forums_footer();
            }
            
            
            if($action == "forums" && $HTTP_POST_VARS['submit'] != "") {
            	$query = mysql_query("SELECT * FROM $db_forum") or die(mysql_error());
            	while($forum = mysql_fetch_array($query)) {
            		$name = "name$forum[fid]";
            		$name = "${$name}";
            		$description = "description$forum[fid]";
            		$description = "${$description}";
            		$dorder = "dorder$forum[fid]";
            		$dorder = "${$dorder}";
            		$delete = "delete$forum[fid]";
            		$delete = "${$delete}";
            
            	if($delete != "") {
            		mysql_query("DELETE FROM $db_forum WHERE fid='$delete'") or die(mysql_error());
            	}
            
            	mysql_query("UPDATE $db_forum SET name='$name', description='$description', dorder='$dorder' WHERE fid='$forum[fid]'") or die(mysql_error());
            }
            
            if($newname != "") {
            	mysql_query("INSERT INTO $db_forum VALUES ('', '$newname', '$newdescription', '$newdorder', '', '')") or die(mysql_error());
            }
            
            echo "Forums updated successfully.";
            }
            

            I only changed it so i can add another field for what category each forum comes under without making the layout look messy.

              im sorry, but your code makes no sense.

              your function ends...

              HTML;
              }
              

              before it begins...

              function cp_forum_row($forum) {
              echo <<< HTML
              <a href="admin.php?action=edit-forums&fid=$forum[fid]">$forum[name]</a><br /><br />
              

                sorry, just forget about that ending part, i'll remove those parts

                  i've now managed to get the edit form showing, but all the boxes are blank for some reason, here is my updated code:

                  function cp_forum_row:

                  function cp_forum_row($forum) {
                  echo <<< HTML
                  <a href="admin.php?action=edit-forums&fid=$forum[fid]">$forum[name]</a><br /><br />
                  

                  function cp_forums_header:

                  function cp_forums_header() {
                  echo <<< HTML
                  <b>Forums</b><br />
                  Here you can edit/create/delete all the forums in your message board.<p>&nbsp;</p>
                  
                  <form method="post" action="admin.php?action=forums">
                  <table width="100%">
                  <tr>
                  <td class="tabletxt2" width="10%"><b>Delete:</b></td>
                  <td class="tabletxt2" width="30%"><b>Forum Name:</b></td>
                  <td class="tabletxt2" width="55%"><b>Description:</b></td>
                  <td class="tabletxt2" width="5%"><b>Order:</b></td>
                  </tr>
                  

                  cp_forums_row:

                  function cp_forums_row($forum) {
                  echo <<< HTML
                  <tr>
                  <td><input type="checkbox" name="delete$forum[fid]" value="$forum[fid]" /></td>
                  <td><input type="text" name="name$forum[fid]" value="$forum[name]" size="30" style="width: 200px" /></td>
                  <td><textarea cols="40" rows="3" name="description$forum[fid]" style="width: 300px; height: 50px">$forum[description]</textarea></td>
                  <td><input type="text" name="dorder$forum[fid]" value="$forum[dorder]" size="2" style="width: 30px" /></td>
                  </tr>
                  

                  cp_forums_footer:

                  function cp_forums_footer() {
                  echo <<< HTML
                  <tr>
                  <td class="tabletxt2" colspan="3"><b>New Forum:</b></td>
                  </tr>
                  <tr>
                  <td colspan="2"><input type="text" name="newname" size="30" style="width: 200px" /></td>
                  <td><textarea cols="40" rows="3" name="newdescription" style="width: 300px; height: 50px"></textarea></td>
                  <td><input type="text" name="newdorder" size="2" style="width: 30px" /></td>
                  </tr>
                  </table><br /><br />
                  <input type="submit" name="submit" value="Modify Forums">
                  </form>
                  

                  code in admin cp:

                  ##### FORUMS #####
                  if($action == "forums" && $HTTP_POST_VARS['submit'] == "") {
                  	$query = mysql_query("SELECT * FROM $db_forum ORDER BY dorder") or die(mysql_error());
                  	while($forum = mysql_fetch_array($query)) {
                  	cp_forum_row($forum);
                  		}
                  	}
                  
                  ##### EDIT FORUMS #####
                  if($action == "edit-forums" && $HTTP_POST_VARS['submit'] == "") {
                  		cp_forums_header();
                  	$query = mysql_query("SELECT name, description FROM cmf_forum WHERE fid='$fid'") or die(mysql_error());
                  	while($forums = mysql_fetch_array($query)) {
                         cp_forums_row($forum);
                  	}	
                  		cp_forums_footer();
                  }
                  

                    ok, got it working 🙂

                    by changing this line:

                    while($forums = mysql_fetch_array($query)) {
                    

                    to this:

                    while($forum = mysql_fetch_array($query)) {
                    

                      ok, now i'm sturggling to get it to edit the forums, for some reason it won't send it to the db after i've changed something

                        for some reason this code is returning "name" for the forum name, "description" for the forum description and "0" for the order of the forum

                        		$name = "name$forum[fid]";
                        		$name = "${$name}";
                        		$description = "description$forum[fid]";
                        		$description = "${$description}";
                        		$dorder = "dorder$forum[fid]";
                        		$dorder = "${$dorder}";
                        		$delete = "$forum[fid]";
                        		$delete = "${$delete}";
                        
                        	mysql_query("UPDATE $db_forum SET name='$name', description='$description', dorder='$dorder' WHERE fid='$fid'") or die(mysql_error());
                        
                          5 days later

                          ok, i can get it to recognise what i enter now, but it won't update the db with what i put

                            ok, i now know what needs looking at.

                            		$name = "name$forum[fid]";
                            		$name = "${$name}";
                            		$description = "description$forum[fid]";
                            		$description = "${$description}";
                            		$dorder = "dorder$forum[fid]";
                            		$dorder = "${$dorder}";
                            		$delete = "$forum[fid]";
                            		$delete = "${$delete}";
                            

                            i know this because i changed it to:

                            		$name = "$fid";
                            		$description = "$description";
                            		$dorder = "$dorder";
                            		$delete = "delete$forum[fid]";
                            		$delete = "${$delete}";
                            

                            and then it put the forum name as the id of the forum

                              Sorry, I'm still confused by all these variable names flying around - I can never keep track of which variables are being used as the names of which other variables (variable array variables, no less!). One thing I can point out is

                              $description = "$description";

                              is a completely useless line. All it does is take the value of $desription, convert it into a string (and I'm guessing it's a string already, so that's a waste of time), and then putting the resulting value back into $description. In other words, it's exactly equivalent to

                              $description=$description;

                              . Once you've understood what it actually means to put a variable in double-quoted strings (hint: there's virtually never any point to writing "$variable"), you'll see that those two pieces of code are equivalent to (and I'm using string concatenation instead of interpolation just to make the point):

                              $name = "name".$forum['fid'];
                              $name = $$name;
                              $description = "description".$forum['fid'];
                              $description = $$description;
                              $dorder = "dorder".$forum['fid'];
                              $dorder = $$dorder;
                              $delete = $forum['fid'];
                              $delete = $$delete;
                              

                              and

                              $name = $fid;
                              $description = $description;
                              $dorder = $dorder;
                              $delete = "delete".$forum['fid'];
                              $delete = $$delete;

                              Respectively. The latter one simplifies further, to:

                              $name = $fid;
                              $delete = ${"delete".$forum['fid']};

                              In short, I think you've got yourself well confused by what you're trying to do and you'll need a machete to clear away the vines. You surely don't need anything this complicated.

                                ok, so do you know of any other way to update 3 values inside 1 forums row?

                                db row: $db_forum, or cmf_forum

                                3 values to update: name, description, dorder

                                $fid grabs the id of the forum that is being edited, so i guess WHERE fid='$fid' is correct

                                  Write a Reply...