wkheathjr
03-04-2008, 07:10 PM
Hello,
I am trying to get my picture gallery up and running. This code was written by an India programmer for me few years ago and now I am starting to learn how to write PHP, but I am still in newbie with some good reading of php code.
Here is what I am trying to do is figure out why my code is not staying with main category after you pick which main category. To understand what I mean, test the live code here (http://www.mason-dixonpark.com/ncdb/postpic.php?do=fillsub). Go ahead and give it a test-drive and see why you can't upload?
<?php
include ("session.php");
?>
<script language="javascript">
function validate()
{
if(document.frmmain.main_cat.value=="")
{
alert("Select Main Category from the list.");
document.frmmain.main_cat.focus();
}
else if(document.frmupload.subcat.value=="")
{
alert("Select Sub Category from the list.");
document.frmupload.subcat.focus();
}
else if(document.frmupload.name.value=="")
{
alert("Enter name.");
document.frmupload.name.focus();
}
else
{
document.frmupload.submit();
}
}
function chkmain()
{
if(document.frmmain.main_cat.value!="")
{
document.frmmain.submit();
}
}
</script>
</head>
<?
if(isset($HTTP_POST_VARS['do']) || isset($HTTP_GET_VARS['do'])) {
$do =(isset($HTTP_POST_VARS['do'])) ? $HTTP_POST_VARS['do'] : $HTTP_GET_VARS['do'];
}
?>
<table width="100%" cellspacing="0" cellpadding="10" border="0" align="center">
<tr>
<td class="bodyline">
<table class="forumline" width="100%" cellspacing="1" cellpadding="4" border="0">
<tr>
<th class="thHead" height="25"><b> Picture Gallery >> Upload Picture </b></th>
</tr>
<tr>
<td class="row1">
<div align="center">
<table width="500">
<tr>
<form name=frmmain method="post" action="?do=fillsub">
<? $result =mysql_query("SELECT * FROM pg_cat ORDER BY name"); ?>
<td>Select main category from the list</td>
<td align="center"><select name="main_cat" onchange="chkmain()">
<option value="">[Select Main Category]</option>
<? while($row =mysql_fetch_array($result)) { ?>
<OPTION value="<?=$row[0]; ?>"<?
if ($row[0]==$main_cat){
echo " selected";
}?>><?=$row[1];?>
</OPTION>
<? } ?>
</select></td>
</form>
</tr>
<form name="frmupload" enctype="multipart/form-data" method="post" action="saveupload.php">
<? if($do=="fillsub") {
$result=mysql_query(("select * from pg_subcat where cat_id = $main_cat"));
?>
<tr>
<td>Select sub category from the list</td>
<td align="center"><select name="subcat">
<option value="">[Select Sub Category]</option>
<? while($row =mysql_fetch_array($result)) { ?>
<OPTION value="<?=$row[0]; ?>"<?
if ($row[3]==$main_cat) {
echo " selected>";
} else {
echo ">";
}
echo $row[1]."</option>";
} ?>
</select></td>
</tr>
</div>
<br><br>
<div align="center">
<table width="500">
<tr>
<td align="left" valign="top">Title</td>
<td align="right"><div align="left">
<input name="name" style="width:230px" type="text"></div>
</td>
</tr>
<tr>
<td align="left" valign=top>Description</td>
<td align="right"><div align="left">
<textarea name="description" cols="35" rows="2"></textarea></div>
</td>
</tr>
<tr>
<td align="left" valign="top">Select Picture to upload</td>
<td><div align="left"><input name="fupload" style="width:300px" type="file"><br></div></td>
</tr>
<tr>
<td> </td>
<input type="hidden" name="main_cat" value="<?=$HTTP_POST_VARS['main_cat'];?>">
<td><div align="right">
<input id="Upload" name="Upload" type="Button" onClick="validate()" value="Upload"></div>
</td>
</tr>
</table>
<? } ?>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
Thank for offering your help!
I am trying to get my picture gallery up and running. This code was written by an India programmer for me few years ago and now I am starting to learn how to write PHP, but I am still in newbie with some good reading of php code.
Here is what I am trying to do is figure out why my code is not staying with main category after you pick which main category. To understand what I mean, test the live code here (http://www.mason-dixonpark.com/ncdb/postpic.php?do=fillsub). Go ahead and give it a test-drive and see why you can't upload?
<?php
include ("session.php");
?>
<script language="javascript">
function validate()
{
if(document.frmmain.main_cat.value=="")
{
alert("Select Main Category from the list.");
document.frmmain.main_cat.focus();
}
else if(document.frmupload.subcat.value=="")
{
alert("Select Sub Category from the list.");
document.frmupload.subcat.focus();
}
else if(document.frmupload.name.value=="")
{
alert("Enter name.");
document.frmupload.name.focus();
}
else
{
document.frmupload.submit();
}
}
function chkmain()
{
if(document.frmmain.main_cat.value!="")
{
document.frmmain.submit();
}
}
</script>
</head>
<?
if(isset($HTTP_POST_VARS['do']) || isset($HTTP_GET_VARS['do'])) {
$do =(isset($HTTP_POST_VARS['do'])) ? $HTTP_POST_VARS['do'] : $HTTP_GET_VARS['do'];
}
?>
<table width="100%" cellspacing="0" cellpadding="10" border="0" align="center">
<tr>
<td class="bodyline">
<table class="forumline" width="100%" cellspacing="1" cellpadding="4" border="0">
<tr>
<th class="thHead" height="25"><b> Picture Gallery >> Upload Picture </b></th>
</tr>
<tr>
<td class="row1">
<div align="center">
<table width="500">
<tr>
<form name=frmmain method="post" action="?do=fillsub">
<? $result =mysql_query("SELECT * FROM pg_cat ORDER BY name"); ?>
<td>Select main category from the list</td>
<td align="center"><select name="main_cat" onchange="chkmain()">
<option value="">[Select Main Category]</option>
<? while($row =mysql_fetch_array($result)) { ?>
<OPTION value="<?=$row[0]; ?>"<?
if ($row[0]==$main_cat){
echo " selected";
}?>><?=$row[1];?>
</OPTION>
<? } ?>
</select></td>
</form>
</tr>
<form name="frmupload" enctype="multipart/form-data" method="post" action="saveupload.php">
<? if($do=="fillsub") {
$result=mysql_query(("select * from pg_subcat where cat_id = $main_cat"));
?>
<tr>
<td>Select sub category from the list</td>
<td align="center"><select name="subcat">
<option value="">[Select Sub Category]</option>
<? while($row =mysql_fetch_array($result)) { ?>
<OPTION value="<?=$row[0]; ?>"<?
if ($row[3]==$main_cat) {
echo " selected>";
} else {
echo ">";
}
echo $row[1]."</option>";
} ?>
</select></td>
</tr>
</div>
<br><br>
<div align="center">
<table width="500">
<tr>
<td align="left" valign="top">Title</td>
<td align="right"><div align="left">
<input name="name" style="width:230px" type="text"></div>
</td>
</tr>
<tr>
<td align="left" valign=top>Description</td>
<td align="right"><div align="left">
<textarea name="description" cols="35" rows="2"></textarea></div>
</td>
</tr>
<tr>
<td align="left" valign="top">Select Picture to upload</td>
<td><div align="left"><input name="fupload" style="width:300px" type="file"><br></div></td>
</tr>
<tr>
<td> </td>
<input type="hidden" name="main_cat" value="<?=$HTTP_POST_VARS['main_cat'];?>">
<td><div align="right">
<input id="Upload" name="Upload" type="Button" onClick="validate()" value="Upload"></div>
</td>
</tr>
</table>
<? } ?>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
Thank for offering your help!