Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help on this editing script...plz

    well i made this script for a little download server site that i own...i thought it would be a good way to learn php..since it involves a wide range of scripts...

    the problem is on this script...i want it so i can edit the details of a record of a file on the database...but in the process...when selecting which category to put it in, since there is 1 dropdown box.that controlls the second one...it refreshes the page...thefore clearing what was in the text boxes...is there a way i can fix this by passing the data when it refreshes...??or another way possibly??here is the code for it...


    <?

    //initilize PHP
    if($rebelservers) {
    include 'header.php';
    if($_POST['submit']) //If submit is hit
    {
    include 'includes/opendb.php';
    $id = $_POST['id'];
    $name = $_POST['name'];
    $filename = $_POST['filename'];
    $uploader = $_POST['uploader'];
    $size = $_POST['size'];
    $category = $_POST['subcat'];
    $description = $_POST['description'];

    $sql = "UPDATE files SET name='$name',filename='$filename',uploader='$uploader',size='$size',catid='$category',description='$ description' WHERE id=$id";

    $result = mysql_query($sql);
    echo("Record ".$id." was edited!");
    }
    else
    {
    ?>
    <?php
    include 'includes/opendb.php';
    $id = $_GET['fileid'];
    $query="SELECT * FROM files WHERE id = $id";
    $result=mysql_query($query);

    mysql_close();

    $row = mysql_fetch_object($result);
    ?>
    <form method="post" action="editfilerecord.php">
    <TABLE>
    <TR><TD>ID:</TD><TD><?=$row->id; ?><input type="hidden" name="id" value="<?=$row->id; ?>"></TD></TR>

    <TR>
    <TD>Name:</TD>
    <TD><INPUT TYPE='TEXT' NAME='name' VALUE='<?=$row->name; ?>' size=30></TD>
    </TR>
    <TR>
    <TD>filename:</TD>
    <TD><INPUT TYPE='TEXT' NAME='filename' VALUE='<?=$row->filename; ?>' size=30></TD>
    </TR><br>
    <TR>
    <TD>Uploader:</TD>
    <TD><INPUT TYPE='TEXT' NAME='uploader' VALUE='<?=$row->uploader; ?>' size=30></TD>
    </TR>
    <TR>
    <TD>Size(in <b>BYTES</b>)<br>Only use numbers, no letters!</TD>
    <TD><INPUT TYPE='TEXT' NAME='size' VALUE='<?=$row->size; ?>' size=30></TD>
    </TR>
    <TR>
    <TD>Description:</TD>
    <TD>
    <textarea name="description" cols="30" rows="5"><?=$row->description; ?></textarea>
    </TD>
    </TR>
    <tr>
    <TD>Category</TD>
    <td>
    <?php
    include 'includes/dbconfig.php';
    include 'includes/opendb.php';
    ?>
    <SCRIPT language=JavaScript>
    function reload(form)
    {
    var val=form.cat.options[form.cat.options.selectedIndex].value;
    var name = form.name.value;

    self.location='?cat=' + val + '&name=' + name;
    }

    </script>
    <?


    ///////// Getting the data from Mysql table for first list box//////////
    $quer2=mysql_query("SELECT * FROM categories WHERE parentid='0' ORDER BY name ASC");
    ///////////// End of query for first list box////////////

    /////// for second drop down list we will check if category is selected else we will display all the subcategory/////
    if(isset($cat) and strlen($cat) > 0){
    $quer=mysql_query("SELECT * FROM categories where parentid=$cat order by name");
    }else{$quer=mysql_query("SELECT * FROM name FROM categories where parentid > '0' order by name"); }
    ////////// end of query for second subcategory drop down list box ///////////////////////////

    ////////// Starting of first drop downlist /////////
    echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Parent Category</option>";
    while($noticia2 = mysql_fetch_array($quer2)) {
    if($noticia2['id']==@$cat){echo "<option selected value='$noticia2[id]'>$noticia2[name]</option>"."<BR>";}
    else{echo "<option value='$noticia2[id]'>$noticia2[name]</option>";}
    }
    echo "</select>";
    ////////////////// This will end the first drop down list ///////////

    ////////// Starting of second drop downlist /////////
    echo "<select name='subcat'><option value='$cat'>Subcategory</option>";
    while($noticia = mysql_fetch_array($quer)) {
    echo "<option value='$noticia[id]'>$noticia[name]</option>";
    }
    echo "</select>";
    mysql_close();
    ////////////////// This will end the second drop down list ///////////


    ?>
    </td>
    </tr>
    <TR>
    <TD></TD><br>
    <TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
    </TR>
    </TABLE>
    </form>

    <?
    } //close the else statement
    include 'footer.php';
    ?>
    <? } else {
    header("Location: login.php");
    }

    ?>

    if you can help me..it will be greatly appreciated...thnx

    ,wagz

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, in javascript function reload you must to put also values of all fields not just to second drop down menu and all works fine. I hope that you know how to do it. (document."form name"."field name".value='<?=$_POST["field name"]?>'
    If you can not find a decision, maybe you have to try to change a problem

    http://www.gunman.co.nr
    http://bglinux.org

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thnx , works...but is there anyway i can make it so it doesnt have such a big url??


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •