Page 1 of 1

Admin page help

Posted: Mon Feb 07, 2011 2:45 am
by ezi_pro
Hi im new to the forum, sorry if this has already been answered before but i just dont know how to word out this question very well.

what i have is a admin page where the user can edit the page. everything has gone smoothly so far and she can edit everything well, but now i want to have a part where she can create a title such as "Child services" then add a list of different services.

the way i would approach this is by creating a form that lets the user input the title with a text box then under the title there is a another textbox which lets her enter her a service and beside each service there is a edit button and delete button. let me visualize this

Add new service text box- add button(when this is submitted it turns into what you see below)

title text box- Edit button - delete button

Add service text box - edit button delete button (i want these to appear as a list)
edit service text box - edit button delete button
(i want these to be inbetween all to be inbetween UL tags and so every line is in between LI tags

ok so im thinking just a plain echo for the add part.

then after the echo a FOR loop with the
query = "select * from (table that the add button submits it too)"
get the result of that query then
desplay the title with a mysql_fetch_row()

then echo "form for the add service"

then another for loop within the for loop to display the services that shes already added.

the problem is how can i get the mysql tables to work for this kind of thing.

i just got the idea while clicking this color button to maybe create a button that just lets her create a bullet point in a textarea.

im going to go and look for a script that lets me have an text box like the one on this forum.

heres the code that i have for the simple create title and insert info anyway so if you want to maybe do it the extreemly complicated way i just mentioned.

Code: Select all

case "homepage":
       
        $query = "select * from homepage";
        $res = queryMysql($query);
        if(mysql_num_rows($res) == 0) {
            $query = "insert into homepage values('Our mission is to be the greatest','This is where you edit your about us')";
            $res = queryMysql($query);
            $error = "default values have been added into your homepage";
            
        }
        if(isset($_POST['edithomepage'])){
            $mstatement = sanitizeString($_POST['mstatement']);

            $aboutus = sanitizeString($_POST['aboutus']);

            $query = "select * from homepage";
            $res = queryMysql($query);
            $row = mysql_fetch_row($res);
            $statement = sanitizeString($row[0]);
            $query = "update homepage set mStatement='$mstatement' where mStatement='$statement'";
            $query2 = "update homepage set aboutus='$aboutus' where mStatement='$statement'";
            $res = queryMysql($query);
             $res = queryMysql($query2);
             $error = "Your homepage has been updated";
        }
        if(isset($_POST['addserviceid'])) {
           if(strlen($_POST['servicename']) > 0 && strlen($_POST['servicetext']) > 0){
               $servicename = sanitizestring($_POST['servicename']);
               $servicetext = sanitizestring($_POST['servicetext']);
               $servicetext = nl2br($_POST['servicetext']);
               $query = "insert into services values('','$servicename','$servicetext')";
               $res = queryMysql($query);
               $error = "Your service has been added";
        }else{$error = "You did not fill in the the services entirely";}

        }

        if(isset($_POST['editserviceid'])){
            if(strlen($_POST['servicename']) > 0 && strlen($_POST['servicetext']) > 0){
                $editserviceid = sanitizeString($_POST['editserviceid']);
                $servicename = sanitizeString($_POST['servicename']);
                $servicetext = sanitizeString($_POST['servicetext']);
                $servicetext = nl2br($_POST['servicetext']);
                $query = "update services set servicename='$servicename' where id='$editserviceid'";
                $res = queryMysql($query);
                $query = "update services set servicetext='$servicetext' where id='$editserviceid'";
                $res = queryMysql($query);
               $error = "Your service has been edited";
            }else{$error = "You did not fill in the the service fields entirely";}
        }
        if(isset($_POST['deleteserviceid'])){
                $deleteserviceid = $_POST['deleteserviceid'];
                $query = "delete from services where id='$deleteserviceid'";
                $res = queryMysql($query);
                $error = "Your service has been deleted";
        }



        $query = "select * from homepage";
        $result = queryMysql($query);
        $row = mysql_fetch_row($result);
        $mstatement = $row[0];
        $aboutus = $row[1];
if(!isset($error)){
            $error = "";
        }

        echo "
            <div id='bodycontent'>
            <center><h2>Edit your homepage</h2>
            <p><a href='admin.php'>Back to admins main menu</a></p>
            <p>Please fill in BOTH the mission statement and the about us</p>
            <p>$error</p>
            <h2>Mission Statement</h2>
                <p><form method='post' action='admin.php?action=homepage'>
                    <textarea name='mstatement' cols='40' rows='4'>$mstatement</textarea></p>
                
            <h2>About us</h2>
                <p><textarea name='aboutus' cols='40' rows='4'>$aboutus</textarea><input type='hidden' name='edithomepage' value='true'><input type='submit' value='edit'></form></p>";
        $query = "select * from services";
        $result = queryMysql($query);
        $num = mysql_num_rows($result);
        print "
            <div id='services'>";
        $query = "select * from services";
        $result = queryMysql($query);
       echo "<p><form method='post' action='admin.php?action=homepage'>Add a service:<input type='text' name='servicename' /></p>
        <p>Add service<textarea name='servicetext' cols='25' rows='20'></textarea></p>
        <input type='hidden' name='addserviceid'>
        </p><input type='submit' value='Add'></form></p>";
        for($j = 0 ; $j < $num ; ++$j){
           $getrow = mysql_fetch_row($result);
           
            echo "<p><form method='post' action='admin.php?action=homepage'>
           Edit Service name:<input type='text' name='servicename' value='$getrow[1]' />
           </p>
           <p>
           Edit Service information: <textarea name='servicetext' cols='25' rows='20'>$getrow[2]</textarea>
           <input type='hidden' name='editserviceid' value='$getrow[0]'>
           <input type='submit' value='edit'></form>
           <form method='post' action='admin.php?action=homepage'>
           <input type='hidden' name='deleteserviceid' value='$getrow[0]'>
           <input type='submit' value='delete'></form>
           </p>";
           
        }

echo "
</div><!-- End of services div -->
</div>";
        break;