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