Author Topic: DROP-DOWN MENU  (Read 494 times)

blabes

  • New Member
  • *
  • Posts: 22
  • Karma: 0
    • View Profile
DROP-DOWN MENU
« on: July 12, 2012, 02:53:56 PM »
What's wrong with my code. It display the followin error message in the drop-down field:

Fatal error: Call to undefined function option_selected() in PHP in C:\xampp\htdocs\imageconcert/index.php on line 27

Here's the code:
<?php
if (isset($_GET["target"]))
{
function option_selected($target, $value)
{
   $v=$_POST[$target];
   if ($v  == $target)
   {
     $selected="selected";
   }
   echo $selected;
}
}
?>
<html>
<head>
<body>
<h1>Ezen az oldalon JPEG, PNG, BMP vagy GIF fájlt tudsz konverálni!</h1>
<form action="function.php" method="post" enctype="multipart/form-data">
Forrás fájl (jpeg,png,bmp vagy gif, max. 2MB):

<input type="file" name="file" value="file" />
<br />
<br />
Célfájl formátuma
<select id="target" name="target">
    <option value="JPEG"><?php echo option_selected("target", "JPEG"); ?>> JPEG </option>
    <option value="JPG"> <?php echo option_selected("target", "JPE"); ?>> JPG </option>
    <option value="BMP"> <?php echo option_selected("target", "BMP"); ?>> BMP </option>
    <option value="GIF"> <?php echo option_selected("target", "GIF"); ?>> GIF </option>
    <option value="PNG"> <?php echo option_selected("target", "PNG"); ?>> PNG </option>
</select>
<br />
<br />

<input type="submit" name="Elküldés" value="Konvertálás"/>
</form>
</body>
</head>
</html>

Andrew

  • iPhone Application & Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 339
  • Karma: 9
  • PHP, MySQL, HTML, and CSS are my playground
    • View Profile
Re: DROP-DOWN MENU
« Reply #1 on: July 12, 2012, 02:56:56 PM »
<?php
if (isset($_GET["target"]))
{
function option_selected($target, $value)
{
   $v=$_POST[$target];
   if ($v  == $target)
   {
     $selected="selected";
   }
   echo $selected;
}
}
?>

Try changing "selected" to "target" you have not used "selected anywhere else as an identifier.
You cannot solve a puzzle if you don't have all the pieces.
Please + my karma if I helped you. <-- over there under my picture.

blabes

  • New Member
  • *
  • Posts: 22
  • Karma: 0
    • View Profile
Re: DROP-DOWN MENU
« Reply #2 on: July 12, 2012, 03:01:20 PM »
Unfortunately it didn't help, the error message is still there. Any other idea?

Andrew

  • iPhone Application & Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 339
  • Karma: 9
  • PHP, MySQL, HTML, and CSS are my playground
    • View Profile
Re: DROP-DOWN MENU
« Reply #3 on: July 12, 2012, 03:07:02 PM »
What are you trying to do with this script? It's not clear to me.
You cannot solve a puzzle if you don't have all the pieces.
Please + my karma if I helped you. <-- over there under my picture.

blabes

  • New Member
  • *
  • Posts: 22
  • Karma: 0
    • View Profile
Re: DROP-DOWN MENU
« Reply #4 on: July 12, 2012, 03:17:59 PM »
Later I'll convert the uploaded jpg, bmp, png image to the format chosen in the drop-down menu.

Andrew

  • iPhone Application & Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 339
  • Karma: 9
  • PHP, MySQL, HTML, and CSS are my playground
    • View Profile
Re: DROP-DOWN MENU
« Reply #5 on: July 12, 2012, 03:19:48 PM »
You were trying to hard! No PHP needed to do this...

PHP Code: [Select]
<html>
<
head>
<
body>
<
h1>Ezen az oldalon JPEGPNGBMP vagy GIF fájlt tudsz konverálni!</h1>
<
form action="function.php" method="post" enctype="multipart/form-data">
Forrás fájl (jpeg,png,bmp vagy gifmax2MB):

<
input type="file" name="file" value="file" />
<
br />
<
br />
Célfájl formátuma
<select id="target" name="target">
    <
option value="JPEG"JPEG </option>
    <
option value="JPG"JPG </option>
    <
option value="BMP"BMP </option>
    <
option value="GIF"GIF </option>
    <
option value="PNG"PNG </option>
</
select>
<
br />
<
br />

<
input type="submit" name="Elküldés" value="Konvertálás"/>
</
form>
</
body>
</
head>
</
html>
You cannot solve a puzzle if you don't have all the pieces.
Please + my karma if I helped you. <-- over there under my picture.

blabes

  • New Member
  • *
  • Posts: 22
  • Karma: 0
    • View Profile
Re: DROP-DOWN MENU
« Reply #6 on: July 12, 2012, 03:23:07 PM »
But in the function.php file how can I refer to the selection in the drop-down menu?

Andrew

  • iPhone Application & Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 339
  • Karma: 9
  • PHP, MySQL, HTML, and CSS are my playground
    • View Profile
Re: DROP-DOWN MENU
« Reply #7 on: July 12, 2012, 03:24:59 PM »
PHP Code: [Select]
$_POST['target'] or $_REQUEST['target']
You cannot solve a puzzle if you don't have all the pieces.
Please + my karma if I helped you. <-- over there under my picture.

blabes

  • New Member
  • *
  • Posts: 22
  • Karma: 0
    • View Profile
Re: DROP-DOWN MENU
« Reply #8 on: July 12, 2012, 03:27:18 PM »
But later, when I chose the type of the target file, how can I tell to PHP which option I selected in the drop-down menu?

RaythXC

  • PHP Programmer & Web-Designer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 395
  • Karma: 10
  • Freelance PHP Programmer/Web-Designer
    • View Profile
    • Rayth.Info
Re: DROP-DOWN MENU
« Reply #9 on: July 12, 2012, 03:28:23 PM »
PHP Code: [Select]
$_POST['target'] or $_REQUEST['target']

Use either of these global variables to access whatever was chosen in the dropdown.
RaythXC - My Home Site
Note: most answers I give come from the php manual located at PHP.Net

Andrew

  • iPhone Application & Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 339
  • Karma: 9
  • PHP, MySQL, HTML, and CSS are my playground
    • View Profile
Re: DROP-DOWN MENU
« Reply #10 on: July 12, 2012, 03:31:00 PM »
Those two variable passes are the Value fields of the options you selected.

put this as the only thing in the function.php file and you will see what i mean.

PHP Code: [Select]
<?php
echo $_POST['target']."<br/>";
echo 
$_REQUEST['target'];
?>
You cannot solve a puzzle if you don't have all the pieces.
Please + my karma if I helped you. <-- over there under my picture.

blabes

  • New Member
  • *
  • Posts: 22
  • Karma: 0
    • View Profile
Re: DROP-DOWN MENU
« Reply #11 on: July 12, 2012, 05:09:44 PM »
I want to convert an uploaded JPG into PNG. I want to store the new file in the uploads/ directory
$ext is the extension of the uploaded file. $target_path is the uploads/ directory. How should I change the following code?

PHP Code: [Select]

if ($ext='jpg' or $ext='jpeg'

{
switch (
$target)
      {}
      case 
"PNG";
      
$image imagecreatefromjpeg($path);
      
imagepng($image'.basename' 'png'100);
      
move_uploaded_file($image,$target_path);
      break;
      }
}
  
 

blabes

  • New Member
  • *
  • Posts: 22
  • Karma: 0
    • View Profile
Re: DROP-DOWN MENU
« Reply #12 on: July 12, 2012, 11:35:08 PM »
I want to convert an uploaded JPG into PNG. I want to store the new file in the uploads/ directory
 $ext is the extension of the uploaded file. $target_path is the uploads/ directory. How should I change the following code?
PHP Code: [Select]

if ($ext='jpg' or $ext='jpeg'

{
 switch (
$target)
 {
 case 
"PNG";
 
$image imagecreatefromjpeg($path);
 
imagepng($image'.basename' 'png'100);
 
move_uploaded_file($image,$target_path);
 break;
 }
 } 

blabes

  • New Member
  • *
  • Posts: 22
  • Karma: 0
    • View Profile
Re: DROP-DOWN MENU
« Reply #13 on: July 12, 2012, 11:39:35 PM »
I also got this error:

Warning: imagepng() [function.imagepng]: gd-png error: compression level must be 0 through 9 in C:\xampp\htdocs\imageconvert\function.php on line 65




 

Andrew

  • iPhone Application & Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 339
  • Karma: 9
  • PHP, MySQL, HTML, and CSS are my playground
    • View Profile
Re: DROP-DOWN MENU
« Reply #14 on: July 13, 2012, 02:56:01 PM »
PHP Code: [Select]

 imagepng
($image'.basename' 'png'100);


Go here for proper usage of imagepng http://php.net/manual/en/function.imagepng.php
Go here for a tutorial on how to upload files to a directory http://www.w3schools.com/php/php_file_upload.asp

You need to do more research before you post with I need help... We are here to help but we are not here to write your script for you. So far you have asked about every step and we have tried to help but these questions my be better in the beginners forums.
You cannot solve a puzzle if you don't have all the pieces.
Please + my karma if I helped you. <-- over there under my picture.