Member Avatar for LastMitch

Hi

I'm having issue with editing the Input Type in 2 different position. I want to edit and add input text in the img. I also want to edit and add input text in the content. What I want to learn is how to add 2 Input Type areas in the same form action

Example:

 <a href="photo.php">
 <img src="images/image_1.jpg" style="width:400px" /> 
 <p id="caption">One to remember </p> 
 </a>

My db name is photography

My table is

CREATE TABLE 'photography' (
 `id` int(13) NOT NULL auto_increment,
 `title` varchar(255) NOT NULL,
 `content` text NOT NULL,
 PRIMARY KEY(`id`)
);

This is my code so far and I'm having issue on how to write it correctly:

<form action="photoimage.php" method="post">
Photo: <input type="" name"" valve=" />
<br />
Caption: <input type="" name"" valve="" />
<br />
</form>

This is my output looks like this:

<a href="photo.php">
<img src="images/<?php echo $title; ?>" style="width:400px" /> 
<p id="caption"><?php echo $content; ?></p> 
</a>

I really appreciate if someone explain to me how write input type correctly. Thanks!

@LastMitch

If you take the code you have so far:

    <form action="photoimage.php" method="post">
    Photo: <input type="" name"" valve=" />
    <br />
    Caption: <input type="" name"" valve="" />
    <br />
    </form>

You would name the fields, i try to keep them as obvious as possibly.

    <form action="photoimage.php" method="post">
    Photo: <input name"photo" valve=" />
    <br />
    Caption: <input name"caption" valve="" />
    <br />
    </form>

So once you get to your photoimage.php you will have a $_POST array available to you:

$_POST['photo']
$_POST['caption']

Then you can use those to add to a DB.

This is a gallery upload script which i used, and modified for my needs:
Click Here

Hope it helps

Member Avatar for LastMitch

@Squidge

Thanks for the reply and explanation! I already had a upload script already. I got that from my previous thread:

http://www.daniweb.com/web-development/php/threads/428335/having-issue-creating-an-upload-file-form

pritaeas & veedeoo explain and show me how to create upload form works.

I apologizes if I didn't explain it clearly. The issue is that when I type in something in the 2 input type, it's not in the database. I mean I can echo and select from my database. It's just that I can't insert the data into the database in order to echo and select my data.

This is the code I'm using to insert the info to my database:

The file is called photoimage.php

<?php 
include ("sql.php");
$msg = "";
if ($_POST){
    $title = $_POST['title'];
    $caption = $_POST['caption'];
    $caption = stripslashes($caption);
if (!$title){
    $msg = "Please Add Name";
} else if (!$caption){
    $msg = "Please Add Caption";
} else {
    $query = mysql_query("INSERT INTO time (title, content) VALUES ('$title', 'caption')") or die (mysql_error());
    $msg = "Submitted";
   }
}
?> 

This is my form:

<form action="photoimage.php" method="post">
Photo: <input type="" name"" valve=" />
<br />
Caption: <input type="" name"" valve="" />
<br /><br />
<input type="submit" name="submit" value="Submit" /><?php echo $msg; ?>
</form>

Everything is on one page which in photoimage.php

I appreciate if you or some other member can explain to me how write input type correctly. Thanks!

Hi LastMitch,

Long time no see :). I have a few school days off.

Anyways, the form input type attributes are the following.. let see if I can them out of my head. I have not seen forms for quite sometime now.

text, hidden, submit, button, image, reset, checkbox, file, radio.. I think I missed a couple, but it is ok, you don't need it for this project.

In your case, the input type attribute will be text. So, in your codes above, we can change it to

    <form action="photoimage.php" method="post">
    Photo: <input type="text" name"" valve=" />
    <br />
    Caption: <input type="type" name"" valve="" />
    <br /><br />
    <input type="submit" name="submit" value="Submit" /><?php echo $msg; ?>
    </form>

Let me re-read my previous post on the link provided above. Normally, I don't remember codes I wrote, because I wrote them as I type my response.

commented: Nice answer +2
Member Avatar for LastMitch

@veedeoo

Long time no see :). I have a few school days off.

Good to see again! Yeah, you should relaxed.

but it is ok, you don't need it for this project.

No, I don't need this for any project. I'm just practicing to get more familiar with the mysql & form function to the database.

The code is just a repeat from my previous thread:

http://www.daniweb.com/web-development/php/threads/429243/cant-echo-message

blocblue explain to me why I didn't echo. In that example I used Textarea.

In this example I'm using the input type. I didn't know I don't need TEXT

I will give you another script to practice on later. Hopefully, I can test it by 3PM east coast time tomorrow.

For now, let me give you the thumbnail/imageProportioning class I wrote to demonstrate Singleton Pattern implementation in OO PHP.

Save this as ThumbIt.class.php.. we will be using this class to precisely create thumbnails.

<?php
## filename ThumbIt.class.php
## simple demonstration on how the singleton pattern can be use in OO PHP..
## written by veedeoo or poorboy 2012 , from daniweb.com ,phpclasses.org, tutpages.com, and yahoo php expert community.
## this script will be available in http://www.phpclasses.org/ and tutpages.com one month from now.

class ThumbIt{
   ## Singleton Pattern begins
   public static $instance = NULL;
   private function __construct(){
                ## if there will be another class needed by this class, you can create an instance here, else just leave this empty
            }
   public static function getInstance() {
                if(!isset(self::$instance)) {

                ## we create an instance of the class ThumbIt if there is no instance running
                  self::$instance = new ThumbIt();
                }
                return self::$instance;
              } 
    private function  __clone() {
      ## don't worry about this, just to make sure there is no clone going in the background.
    }

    ## end of singleton pattern
    ## class ThumbIt methods begins 
    public function createThumb($name, $maxW, $maxH, $image_path, $thumb_path, $outname) {

    $ext = substr($name, strrpos($name, ".") + 1) ;
    switch (strtolower($ext)) {
        case "jpg":
        case "jpeg":
            $img = imagecreatefromjpeg($image_path.$name) ;
            $size = self::ResizeMath($maxW, $maxH, $img) ;
            $size[0] = $maxW ;
            $size[1] = $maxH ;
            $img2 = imagecreatetruecolor($size[0], $size[1]) ;
            imagecopyresized($img2, $img, 0, 0, 0, 0, $size[0], $size[1], $size[2], $size[3]) ;
            imagejpeg($img2, $thumb_path.$outname) ;
            return true ;
            break ;
        case "png":
            $img = imagecreatefrompng($image_path.$name) ;
            $size = self::ResizeMath($maxW, $maxH, $img) ;
            $size[0] = $maxW ;
            $size[1] = $maxH ;
            $img2 = imagecreatetruecolor($size[0], $size[1]) ;
            imagecopyresampled($img2, $img, 0, 0, 0, 0, $size[0], $size[1], $size[2], $size[3]) ;
            imagepng($img2, $thumb_path.$outname) ;
            return true ;
            break ;
        case "gif":
            $img = imagecreatefromgif($image_path.$name) ;
            $size = self::ResizeMath($maxW, $maxH, $img) ;
            $size[0] = $maxW ;
            $size[1] = $maxH ;
            $img2 = imagecreatetruecolor($size[0], $size[1]) ;
            imagecopyresampled($img2, $img, 0, 0, 0, 0, $size[0], $size[1], $size[2], $size[3]) ;
            imagegif($img2, $thumb_path.$outname) ;
            return true ;
            break ;
        default:
            return false ;
            break ;
    }
}
    private function ResizeMath($maxW, $maxH, $img) {
        $imageW = imagesx($img) ;
        $imageH = imagesy($img) ;
        if ($imageW <= $maxW && $imageH <= $maxH) {
            $thumbW = $imageW ;
            $thumbH = $imageH ;
    }
        else {
                if ($imageW > $imageH) {
                 ## this is wide image
                    $qW = $maxW / $imageW;
                    $thumbW = $imageW * $qW ;
                    //$thumbH = $maxW / $imageW * $imageH ;
                    $thumbH = $imageH * $qW;
                }
                elseif($imageH > $imageW){
                    ## we got tall image
                    $qH = $maxH / $imageH;
                    $thumbH = $imageH * $qH;
                }
                else {
                    $thumbH = $maxH ;
                    $thumbW = $maxW ;
                }
            }
    $thumbW = round($thumbW) ;
    $thumbH = round($thumbH) ;
    $thesize = array($thumbW, $thumbH, $imageW, $imageH) ;
    return $thesize ;
    }   
}

Tomorrow, I will post the remaining files..

Member Avatar for LastMitch

@veedeoo

Nice script. Is this related to the code (upload form) about one about month ago?

So you are intended to donate this code to daniweb.com ,phpclasses.org, tutpages.com, and yahoo php expert community?

It's really very generous of you.

I don't think Daniweb has a library yet to put codes in section.

I will give you another script to practice on later.

I think you already gave me that upload script already for me to practice. It's pretty neat.

You know this is not the first time you ran off topic but it's OK.

You know ... you help me a lot in the past ...

So I'm thankful and I don't mind ...

I kinda got used to you posting codes not related to topic. =)

Member Avatar for LastMitch

@veedeoo

I mark solve because you asking my question and I figure it out base on your answer.

Save that code for another day! You're starting school soon. Just focus on that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.