<?php
$msg="";
$image1="";
$image1_err="";
//if upload button is pressed 
if(isset($_POST['upload'])){
$target="images/".basename($_FILES['image']['name']);

$db=mysqli_connect("localhost","root","","categories");
$image=$_FILES['image']['name'];
$text=$_POST['text'];

if(isset($_POST['electro'])){
    $sql="INSERT INTO electronic(image,text) VALUES ('$image','$text')";
mysqli_query($db,$sql);
}
//move image to a file
if(move_uploaded_file($_FILES['image']['tmp_name'],$target)){
    $msg="Image uploaded successfully";
}else{
    $msg="There was a problem uploading image";
}

}

?> <!DOCTYPE html> <html> <head> <title>Image Upload</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="content"> <?php
    $db=mysqli_connect("localhost","root","","categories");
    $sql="SELECT * FROM electronic";    
    $result=mysqli_query($db,$sql);

    while($row =mysqli_fetch_array($result)){
        echo "<div id='img_div'>";
        echo "<img src='images/".$row['image']."'>";
        echo "<p>" .$row['text']."</p>";
        echo "</div>";
    }
?> 

Recommended Answers

All 4 Replies

Please add what line you think the issue is at and "what is the issue" to this. As it stands your post looks to be a how-to.

in line 13,i try to get the value from combo box option which is<option value=“ electronic” name=“electro”> electronic</option>. But I don’t know how to get it. Can u help me?

Erk! Do not use this code as you are wide open to sql injection.

commented: "Welcome Little Bobby Tables" +15

i try to get the value from combo box option which is<option value=“ electronic” name=“electro”> electronic</option>

Are you been deliberately obtuse? Why didn't you include the markup for the select? Why have you still not included it?

The quote above relates to the option and if set the value, "electronic" will be passed using the name attached to the <select> tag - whatever that is. The name attached to the <option> tag ("electro") will not be passed.

Sorry if it sounds negative, but we do not have crystal balls that have access to all your code and markup.

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.