How to get the value of input type image in PHP

How to get the value of input type image in PHP : Hello Friends, In this article you will going to see the discussion regarding how one can get value of the image with using programming language PHP.

We will see the discussion in details, it can be easily understand who are experienced and also easily understand by PHP, HTML, and CSS. Here HTML is hypertext markup language used design purpose and PHP is hypertext preprocessor.

Lets Checkout How to get the value of input type image in PHP

With the Help of below code snippets you can understand easily using the code of PHP and HTML and CSS.

Below is code snippets for CSS :

<style>
.userInputImageone{
	border:2px solid red;
}
.userInputImagetwo{
	border:2px solid red;
}
.userInputImagethree{
	border:2px solid red;
}
</style>

The above class name used in the style sheet is add as class name in the html tags such as table, input .

With the help help of the code snippets you can understand how it is used and the way it is help full.

In the HTML, Used three input type of image and input type text box and one input type button.

In this complete scripts of PHP language what i have try to do is, simply on click of button posting the value of that selected input type radio in which i am using the exact value of the image.

The value of the image you can get using the database by fetching the value from database and to get the value from the database you have to use select statement and execute sql query and add the value to the input type textbox.

The value in textbox is the value of the text box.

To do this you have to first insert the value of the image on submit of form value of the selected image.

First you have to add the code for connecting the connection database. You can use the below code snippets for connecting database.

<?php 
   /* database configuaration */
   define('DB_SERVER', 'localhost');
   define('DB_USERNAME', 'root');
   define('DB_PASSWORD', '');
   define('DB_DATABASE', 'phpeducation');
   $con  = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
 
   // Check connection
	if (mysqli_connect_errno()) {
	  echo "Failed to connect to MySQL: " . mysqli_connect_errno();
	  exit();
	}
	
?>

But In this case i have not insert value to database. Just I am simply posting the value of the form and add the post value to input type textbox.

But you can checkout full detail regarding Insert, Update And Delete of Multiple Image. It is very much helpful to you. Below is Link you can go through it.

Below is the code snippet for adding the value to textbox (Code of HTML and PHP)

<body>
	<div style="background-color:#e5bcbc;" align="center">
		<h1>How to get the value of input type image in PHP</h1>
		<form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
		Image Value : <br><input class="inputVal" id="ImageValue" type="text" name="inputName" value="<?php echo(isset($_POST['ImageVal'])?$_POST['ImageVal']:'');?>"></br>
		<input type="radio" id="userInputImage" value="img/personeone.jpg" name="ImageVal">
		Image one : <br><input class="inputVal inputImgValone" src="img/personeone.jpg" type="image" name="inputImageone" ></br>
		<input type="radio" id="userInputImage" value="img/personetwo.jpg" name="ImageVal">
		Image two : <br><input class="inputVal inputImgValtwo" src="img/personetwo.jpg" type="image" name="inputImagetwo" ></br>
		<input type="radio" id="userInputImage" value="img/personethree.jpg" name="ImageVal">
		Image three : <br><input class="inputVal inputImgValthree" src="img/personethree.jpg" type="image" name="inputImagethree" ></br>
		<input type="submit" value="SUBMIT">
		</form>
	</div>
	
</body>
Getting the value of the image in text box.

Conclusion:

Finally done with the solution for the input type of image. If you have any doubt regarding this you can comment on it. And if need you complete code regarding insert update and delete of image then you check the above link.

Thank you. Hope you like article.

Leave a Reply

Your email address will not be published.