简体   繁体   中英

Save multiple images in database

I have 3 images that changes on click, and I want to save what ever the user choose from the images to the database so it will be uploaded in another page, I'm not sure if it's possible that's why I'm asking.

<form name="massage-box" id="inp" class="con" action="http://localhost/Folder/massage.php" method="POST" >
            <textarea name="textmassage" id="massage"  type="text"  class="inputs inputtotextfeild" placeholder="Write your massage here ." required></textarea>
            <img class="icn1" src="pic1.png" id="geticon" onclick="iconfun()" >
            <img class="icn2" src="pic11.png" id="geticon2" onclick="iconfun2()">
            <img class="icn3" src="pic111.png" id="geticon3" onclick="iconfun3()">
            <br>
            <br>
            <br>
            <button name="submit" type="submit" class="sbmtcom">Post massage </button>
        </form>

I'll provide one of the three images java script code because all of them has the same coding way

var counter = 0,
    gallery = ["pic1.png", "pic2.png", "pic3.png", "pic4.png", "pic5.png", "pic6.png"],
   iconfun = function () {
        document.getElementById("geticon").src = gallery[counter];
        counter++;
        if (counter >= gall

ery.length) {
            counter = 0;
}

and here is the PHP code:

if(isset($_POST['submit']))
{    
     $textmassage = $_POST['textmassage'];
     $geticon = $_POST['geticon'];
     $geticon2 = $_POST['geticon2'];
    $geticon3 = $_POST['geticon3'];
    
     $sql = "INSERT INTO massageform (textmassage,geticon,geticon2,geticon3)
     VALUES ('$textmassage','$geticon',' $geticon2',' $geticon3')";
}

   

If you only want to save them temporarily would you consider putting them into the session?

$_SESSION['geticon3'] = $_POST['geticon3'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM