I have a code below where it looks for an ImageId by seeing what is entered in 'ImageFile[]' and then I use INSERT VALUES to insert the values (at the moment I am using echo $questionsql). The problem though is that the value is left blank when I echo it. Also I am getting undefined index notice for imageFile[]. $insertquestion = array();
$imagequery = "SELECT ImageId FROM Image WHERE (ImageFile = '". mysql_real_escape_string($_POST['imageFile'])."')";
$imagers = mysql_query($imagequery);
$imagerecord = mysql_fetch_array($imagers);
$imageid = $imagerecord['ImageId'];
$insertquestion[] = "'".
mysql_real_escape_string( $imageid ) ."'";
$questionsql = "INSERT INTO Question (ImageId)
VALUES (" . implode('), (', $insertquestion) . ")";
echo($questionsql);
The reason I believe it echos a blank value for 'imageFile[]' and why it is stating 'imageFile[]' is undefined is because in the <form>
below, there is no imageFile[]. The imageFile[] is in the javascript code and it is appended into the form table.
So what I want to know is how can I get it so I can get a hidden input which matches the appended ImageFile'[]' into the form code so that when I post imageFile[] in the next page where the php code is, I don't get an undefined index and I won't get a blank value for 'imageFile[]?
Below is the javascript and form code:
<script>
function insertQuestion(form) {
var $tbody = $('#qandatbl > tbody');
var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
var $image = $("<td class='image'></td>");
var $imagefile = $('<input />')
.attr({
type: 'file',
name: 'imageFile[]',
class: 'imageFile'
});
$tr.append($qid);
$tr.append($image);
$tbody.append($tr);
}
</script>
<form id="QandA" action="insertQuestion.php" method="post" >
<table id="qandatbl" align="center">
<thead>
<tr>
<th class="image">Image</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</form>