...

View Full Version : Need help on this editing script...plz



wagz
09-17-2005, 09:42 AM
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 :D

,wagz

gunman
09-17-2005, 01:39 PM
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"]?>';)

wagz
09-17-2005, 11:13 PM
thnx :D, works...but is there anyway i can make it so it doesnt have such a big url??



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum