nethken nethken - 1 year ago 65
jQuery Question

Pass the value of an image through modal to another page

Hello how can i pass the value of an image through modal to another page? When i click the edit button a modal will popup and all the data fetched are in there and after i click the "yes" it will pass all the data in my form to another page. Im new to php and starting to learn it. Can someone give me ideas how to do it?

here is my form inside the modal.

<form method="POST" enctype="multipart/form-data" action ="edit2.php?newsid=<?=$row['news_id']?>">
<div class="form-group">
<label for="title">News Title</label>
<input type="text" name="titles" class="form-control title" id="title" placeholder="News Title" value="<?php echo $row['news_title']; ?>">

<div class="form-group">
<label for="date">Date</label>
<input type="text" name="dates" class="form-control date" id="date" placeholder="Date" value="<?php echo $row['news_date']; ?>"s>

<div class="form-group">
<label for="content">News Content</label>
<textarea class="form-control content" name="contents" rows="5" id="content"><?php echo $row['news_content']; ?></textarea>

<img id="blah" src="<?php echo $row['news_image']; ?>" width="200px" height="140px"/>
<input id="image" name="image" class="fileupload" type="file" accept="image/*"/>


<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class='btn btn-info left-margin'>Yes</a>

here is the edit2.php. this is where will i pass the image value and edit it.



$newsid = $_GET['newsid'];
$title = $_POST['titles'];
$date = $_POST['dates'];
$content = $_POST['contents'];


$title = $_POST['titles'];
$date = $_POST['dates'];
$content = $_POST['contents'];
$sql ="UPDATE news SET news_title ='$title', news_date ='$date', news_content = '$content', news_image = '$newsimage' WHERE news_id = '$newsid'";
mysqli_query($con, $sql);


Answer Source

File uploading is a bit different than a normal "text" upload using f.e. an <input type="text">. The difference is, that mainly because of security this is wrapped into a protected FormData object.

A normal <input type="text"> will be accessible using $_POST['somename']. Files can be accessed using the $_FILES command.

A more brief explanation of working with files using PHP can be found here:

And maybe a more useful article will be this:

Have fun!

Best regards,