Jump to content

Dropdown list problem


xavier.rayne

Recommended Posts

I want to create a dropdown list to select group name from table groupName:

 

Table Structure for groupName:

CREATE TABLE `groupname` (
  `Id` int(11) NOT NULL auto_increment,
  `description` text,
  `image` text,
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

which Id is the group id, description is the group name.

 

I want to select group name from list and i just want to keep the group id and the group name in another table. How to do it? Please help me :-[

 

One more question. Why the dropdown list only available for one time  ??? Thanks 

 

Below is my code:

<?php
session_start();
define ("MAX", 32); 
if(isset($_SESSION["session_post"]))
{
if ($_SESSION['session_post'] == "admin")
{
include("../config_pic.php");
?>
<?php 
// This page allows users to upload files to the server.
if (isset($_POST['submit']))
{ 
// Add record to database. 
$gid      = $_POST['grpid']; 
$queryA	 = "SELECT * FROM images WHERE grpId='$gid'";  
$resultA = mysql_query($queryA);
$count 	 = mysql_num_rows($resultA);
$rowA	 = mysql_fetch_array($resultA);
$path	 = "http://localhost/photo_album/mall/images/";	
$filename = "";		

if ($count < MAX)
{
	if ($_FILES['upload']['name'] != "")
	{	
		// Create the file name and path name		
		if ($_FILES['upload']['name'] != ""){
		$filename 	= $_FILES['upload']['name'];
		$path		= $path.$filename;
	}
	else{
		$path = "";
	}
	$gid      = $_POST['grpid']; 
	$queryI 	= "INSERT INTO images (name, grpId) VALUES ('$filename', '$gid')"; 
	$resultI	= @mysql_query ($queryI);	

	}
}
else
{
	echo "<font color='red'>You have reach the maximum limit of photo upload!<br>If you wish to upload more photos, please delete the photos you don't want.";

}
$suceed = 0;
if ($filename != ""){
if(move_uploaded_file($_FILES['upload']['tmp_name'], "mall/images/$filename")){
	$suceed = 1;}
else
	{$suceed = 0;}	
}		
if($suceed ==1)	
{$msg="The file has been uploaded!";}
else {$msg="<font color='red'>Your submission could not be processed due to a system error. We apologize for any inconvenience.";}
mysql_close(); 
} 
?>
<html>
<body>
<p align="right"><a href="gallery.php">Back To Gallery</a></p>
<br><br>
<table border="0" align="center" width="400">
<tr><td>	
<table cellpadding="3" cellspacing="0" border="0" valign="top" align="center" width="400">
<tr><td><span style="color:#FF0000; font-size:13px"><?php echo (isset($msg)) ? $msg : " <br>" ?></span></td></tr>
</table>
</td></tr>
<tr><td>
<table cellpadding="5" cellspacing="0" border="0" valign="top" align="center" width="400" bgcolor="#CCCCFF">

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000000">Please fill in the group name that you would like to upload images before starting upload.Thanks for cooperation.
        <tr><td colspan="2" bgcolor="#000000" align="center"><span style="color:#FFFFFF; font-size:15px"><strong>Upload Photo</strong></span> </td>
        </tr>
<tr><td colspan="2" height="10"></td></tr>	
<tr><td width="80" align="center"><span style="color:#000000; font-size:13px"><b>Group:</b></span></td>
    <td width="300"><!--<input type="text" name="desc" size="30"/>--><select name="description">
  <option>Group</option>
    <?php
		 $result=mysql_query("Select Id,description from groupname ORDER BY Id");
		 while($row=mysql_fetch_array($result))
		  {
		  ?>
               <option value="<?php echo $row['Id'];?>"><?php echo $row['description']; $grpid=$row['Id'];?> </option>
               <?php
		  }?>
             </select> <input type="hidden" name="grpid" value="<?php echo $row['Id'] ?>"></td></tr>
  	<tr><td width="80" align="center"><span style="color:#000000; font-size:13px"><b>Image:</b></span></td>
    <td width="300"><input type="file" name="upload" size="30"/></td></tr>
<!--   <input name="description" type="hidden" size="65">-->
  <tr><td colspan="2" align="center">
      <input type="submit" name="submit" value="Submit" />
      <input type="reset" name="Reset" value="Reset">
  </td></tr>
</form><!-- End of Form -->  
  </table>
  </td></tr>
  <tr><td> </td></tr>
  <tr><td align="right"><a href="index.php?status=signout">Sign Out</a></td></tr>
  </table>
  </body>
  </html> 
<?php
}
else
{header("Location:index.php?msg=You do not have the authority to access the page");}	
}
else
{header("Location:index.php");} 
?>

Thanks

Link to comment
Share on other sites

Why the dropdown list only available for one time?

 

After i have choose the group name for once, the dropdown list will not be able to show all the group name..and the image could not be uploaded.Why??

What's wrong with my codes?Please help me...

 

<?php
session_start();
define ("MAX", 32); 
if(isset($_SESSION["session_post"]))
{
if ($_SESSION['session_post'] == "admin")
{
include("../config_pic.php");

// This page allows users to upload files to the server.
if (isset($_POST['submit']))
{ 
// Add record to database. 
$gid     = $_POST['grpid']; 
$queryA	 = "SELECT * FROM images WHERE grpId='$gid'";  
$resultA = mysql_query($queryA)or die(mysql_error());
$count 	 = mysql_num_rows($resultA); 
$rowA	 = mysql_fetch_array($resultA);
$path	 = "http://localhost/photo_album/mall/images/";	
$filename= "";		

if ($count < MAX)
{
	if ($_FILES['upload']['name'] != "")
	{	
		// Create the file name and path name		
		if ($_FILES['upload']['name'] != ""){
		$filename 	= $_FILES['upload']['name'];
		$path		= $path.$filename;   
	}
	else{
		$path = "";
	}
	$gid      	= $_POST['grpid'];   
	$queryI 	= "INSERT INTO images (name, grpId) VALUES ('$filename', '$gid')"; 
	$resultI	= @mysql_query ($queryI);	
	}
}
else
{
	echo "<font color='red'>You have reach the maximum limit of photo upload!<br>If you wish to upload more photos, please delete the photos you don't want.";

}
$suceed = 0;
if ($filename != "" && $gid != ""){
if(move_uploaded_file($_FILES['upload']['tmp_name'], "mall/images/$filename")){
	$suceed = 1;}
else
	{$suceed = 0;}	
}		
if($suceed ==1)	
{$msg="The file has been uploaded!";}
else {$msg="<font color='red'>Your submission could not be processed due to a system error. We apologize for any inconvenience.";}
mysql_close(); 
} 
?>
<html>
<body>
<p align="right"><a href="gallery.php">Back To Gallery</a></p>
<br><br>
<table border="0" align="center" width="400">
<tr><td>	
<table cellpadding="3" cellspacing="0" border="0" valign="top" align="center" width="400">
<tr><td><span style="color:#FF0000; font-size:13px"><?php echo (isset($msg)) ? $msg : " <br>" ?></span></td></tr>
</table>
</td></tr>
<tr><td>
<table cellpadding="5" cellspacing="0" border="0" valign="top" align="center" width="400" bgcolor="#CCCCFF">
Please select the group name that you would like to upload images before starting upload.Thanks for cooperation.
<form id="form1" name="form1" method="post" action="upload_image.php"><center>
<table>
  <tr>
    <td colspan="2">Please select group name:    
      <select name="grpId" onChange='this.form.submit()'>
  		<option>Group</option>
    <?php
		 $result=mysql_query("Select Id, description from groupname ORDER BY Id");
		 while($row=mysql_fetch_array($result))
		  {
		  ?>
               <option value="<?php echo $row['Id'];?>"><?php echo $row['description'];?> </option>
               <?php
		  }?>
             </select> 	  </td></tr></table></form>
<p><p>
<table cellpadding="5" cellspacing="0" border="0" valign="top" align="center" width="400" bgcolor="#CCCCFF">
<form id="form1" name="form1" method="post" action="upload_image.php">
  <? 
	include("../config_pic.php");
	$gid     = $_POST['grpId']; 
	$desc    = $_POST['description'];
	$query4  = "SELECT * FROM images where grpId='$gid'";
	$result4 = mysql_query($query4) or die (mysql_error());
	$count 	 = mysql_num_rows($result4);
	$row4    = mysql_fetch_array($result4);
	$path	 = "http://localhost/photo_album/mall/images/";	
	$filename= ""; 	
?>
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
        <tr><td colspan="2" bgcolor="#000000" align="center"><span style="color:#FFFFFF; font-size:15px"><strong>Upload Photo</strong></span> </td>
        </tr>
<tr><td colspan="2" height="10"></td></tr>	
<tr><td width="80" align="center"><span style="color:#000000; font-size:13px"><b>Group:</b></span></td>
    <td width="300"><input type="text" name="grpid" value="<?php echo $gid ?>"></td>
</tr><!--<input type="hidden" name="grpid" value="<?php echo $gid ?>">-->
  	<tr><td width="80" align="center"><span style="color:#000000; font-size:13px"><b>Image:</b></span></td>
    <td width="300"><input type="file" name="upload" size="30"/></td></tr>
  <tr><td colspan="2" align="center">
      <input type="submit" name="submit" value="Submit" />
      <input type="reset" name="Reset" value="Reset">
  </td></tr>
</form><!-- End of Form -->  
  </table>
  <tr><td> </td></tr>
  <tr><td align="right"><a href="index.php?status=signout">Sign Out</a></td></tr>
  </table>
  </body>
  </html> 
<?php
}
else
{header("Location:index.php?msg=You do not have the authority to access the page");}	
}
else
{header("Location:index.php");} 
?>

 

Thanks :)

Link to comment
Share on other sites

Hi,there :)

 

I've manage to settle the uploading problem but the dropdown list is still available for once only. Why ???

 

Here is my new edited code:

<?php
session_start();
define ("MAX", 32); 
if(isset($_SESSION["session_post"]))
{
if ($_SESSION['session_post'] == "admin")
{
include("../config_pic.php");

// This page allows users to upload files to the server.
if (isset($_POST['submit']))
{ 
include("../config_pic.php");
// Add the record to the database.
$gid     = $_POST['grpid']; 
$queryA	 = "SELECT * FROM images WHERE grpId='$gid'";   
$resultA = mysql_query($queryA);
$count 	 = mysql_num_rows($resultA);
$row	 = mysql_fetch_array($resultA);
$id		 = $row['Id'];
$path	 = "http://localhost/photo_album/mall/images/";	
$filename = "";		

if ($count < MAX)
{
	if ($_FILES['upload']['name'] != "")
	{	
		// Create the file name and path name		
		if ($_FILES['upload']['name'] != ""){
		$filename 	= $_FILES['upload']['name'];
		$path		= $path.$filename;   
	}
	else{
		$path = "";
	}
   
	$queryI 	= "INSERT INTO images (name, grpId) VALUES ('$filename', '$gid')"; 
	$resultI	= @mysql_query ($queryI);	
	}
}
else
{
	echo "<font color='red'>You have reach the maximum limit of photo upload!<br>If you wish to upload more photos, please delete the photos you don't want.";

}
$suceed = 0;
if ($filename != "" && $gid != ""){
if(move_uploaded_file($_FILES['upload']['tmp_name'], "mall/images/$filename")){
	$suceed = 1;}
else
	{$suceed = 0;}	
}		
if($suceed ==1)	
{$msg="The file has been uploaded!";}
else {$msg="<font color='red'>Your submission could not be processed due to a system error. We apologize for any inconvenience.";}
mysql_close(); 
} 
?>
<html>
<body>
<p align="right"><a href="gallery.php">Back To Gallery</a></p>
<br><br>
<table border="0" align="center" width="400">
<tr><td>	
<table cellpadding="3" cellspacing="0" border="0" valign="top" align="center" width="400">
<tr><td><span style="color:#FF0000; font-size:13px"><?php echo (isset($msg)) ? $msg : " <br>" ?></span></td></tr>
</table>
</td></tr>
<tr><td>
<table cellpadding="5" cellspacing="0" border="0" valign="top" align="center" width="400" bgcolor="#CCCCFF">
Please select the group name that you would like to upload images before starting upload.Thanks for cooperation.
<form id="form1" name="form1" method="post" action="upload_image.php"><center>
<table>
  <tr>
    <td colspan="2">Please select group name:    
      <select name="grpId" onChange='this.form.submit()'>
  		<option>Group</option>
    <?php
		 $result=mysql_query("Select Id, description from groupname ORDER BY Id");
		 while($row=mysql_fetch_array($result))
		  {
		  ?>
               <option value="<?php echo $row['Id'];?>"><?php echo $row['description'];?> </option>
               <?php
		  }?>
             </select> 	  </td></tr></table></form>
<p><p>
<table cellpadding="5" cellspacing="0" border="0" valign="top" align="center" width="400" bgcolor="#CCCCFF">
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
        <tr><td colspan="2" bgcolor="#000000" align="center"><span style="color:#FFFFFF; font-size:15px"><strong>Upload Photo</strong></span> </td>
        </tr>
<tr><td colspan="2" height="10"></td></tr>	
<?php $gid = $_POST['grpId'] ?>
<tr><td width="80" align="center"><span style="color:#000000; font-size:13px"><b>Group:</b></span></td>
    <td width="300"><input type="text" name="grpid" value="<?php echo $gid ?>"></td></tr>
  	<tr><td width="80" align="center"><span style="color:#000000; font-size:13px"><b>Image:</b></span></td>
    <td width="300"><input type="file" name="upload" size="30"/></td></tr>
  <tr><td colspan="2" align="center">
      <input type="submit" name="submit" value="Submit" />
      <input type="reset" name="Reset" value="Reset">
  </td></tr>
</form><!-- End of Form -->  
  </table>
  <tr><td> </td></tr>
  <tr><td align="right"><a href="index.php?status=signout">Sign Out</a></td></tr>
  </table>
  </body>
  </html> 
<?php
}
else
{header("Location:index.php?msg=You do not have the authority to access the page");}	
}
else
{header("Location:index.php");} 
?>

 

Anyone please help me.

Thanks..

 

Link to comment
Share on other sites

do you mean that it instantly submits?

 

I created a dropdown list that display all the available group name to let users to choose a group that they want to upload photos..but after the user choosing a group and submit one image, the dropdown list cannot display any group name to let users to choose again. Why???

 

Thanks :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.