I have a problem posting text fields and uploading a picture at the same time, at the moment I can either upload a picture or post the text fields. How can I post it all at the same time using one button?
$photo_form = '<form id="photo_form" enctype="multipart/form-data" method="post" action="php_parsers/status_system.php">';
$photo_form .= '<select name="gallery" required>';
$photo_form .= '<option value="Cover">Cover</option>';
$photo_form .= '</select>';
$photo_form .= ' <b>Browse:</b> ';
$photo_form .= '<input type="file" name="photo" accept="image/*" required>';
$photo_form .= '<p><input type="submit" value="Upload"></p>';
$photo_form .= '</form>';
$status_ui = "";
$status_ui = '<div><textarea id="statustext" onkeyup="statusMax(this,500)" placeholder="Description field"></textarea>';
$status_ui .= $photo_form;
$status_ui .= '<textarea id="statustext2" onkeyup="statusMax(this,200)" placeholder="Description field 2."></textarea></div>';
$status_ui .= '<button id="statusBtn" onclick="postToStatus(\'status_post\',\'a\',\''.$u.'\',\'statustext\',\'statustext2\')">Post</button>';
To Maximus2012
$status_ui = "";
$status_ui .= '<div><textarea id="statustext" name="statustext" onkeyup="statusMax(this,500)" placeholder="Description field"></textarea>';
$status_ui .= '<textarea id="statustext2" name="statustext2" onkeyup="statusMax(this,200)" placeholder="Description field 2."></textarea></div>';
$photo_form = '<form id="photo_form" enctype="multipart/form-data" method="post" action="php_parsers/status_system.php">';
$photo_form .= '<select name="gallery" required>';
$photo_form .= '<option value="Cover">Cover</option>';
$photo_form .= '</select>';
$photo_form .= ' <b>Browse:</b> ';
$photo_form .= '<input type="file" name="photo" accept="image/*" required>';
$photo_form .= $status_ui ;
$photo_form .= '<p><input type="submit" value="Upload"></p>';
$photo_form .= '</form>';
echo $photo_form ;
I can still only upload image with this code but when I use
$photo_form .= '<p><button id="statusBtn" onclick="postToStatus(\'status_post\',\'a\',\''.$u.'\',\'statustext\',\'statustext2\')">Post</button></p>';
instead of
$photo_form .= '<p><input type="submit" value="Upload"></p>';
everything is processed but text parts are insterted in one row and image in another.
This is my postToStatus function:
function postToStatus(action,type,user,ta,te){
var data = _(ta).value;
var data2= _(te).value;
if(data == "" && data2 == ""){
alert("Please fill in all fields");
return false;
}
I made some adjustments to my image parsing script so text and image are placed in the same row, since image is uploaded after text, instead of inserting filename into a new row script is now updating last row created by that user on his profile. Now I just need to prevent posting the form if any of the fields is blank.
$sql = "UPDATE status SET filename = '$db_file_name' WHERE author = '$log_username' && account_name = '$log_username' ORDER BY id DESC LIMIT 1";