したがって、jquery$.ajaxを使用してphpスクリプトを呼び出すフォームがあります。私の問題は、テキスト入力とファイル入力または画像の両方を送信する方法が見つからないことです。画像だけでなく、テキストも送信できます。
これが私が得たものです:
Javascript:
そうしないと {
$.ajax({
type: 'POST',
url: 'test1.php',
cache: false,
data: $(".contact_form").serializeArray(),
success: function (data) {
if (data == "error") {
$('.success_box').hide();
$('.error_box').show();
}
else {
$('#sname').val('');
$('#email').val('');
$('#title').val('');
$('#message').val('');
$('#photo1').val('');
$('#photo2').val('');
$('.error_box').hide();
$('.success_box').show();
}
}
});
}
PHP:
<?php
$sname=$_POST['sname'];
$email=$_POST['email'];
$title=$_POST['title'];
$description=$_POST['message'];
$photo1=$_FILES['photo1']['tmp_name'];
$photo2=$_FILES['photo2']['tmp_name'];
$link = mysql_connect("localhost","root","root");
if (!$link) {
die(mysql_error());
echo('link stop');
}
$db = mysql_select_db("test");
if (!$db) {
die(mysql_error());
echo('braaahh');
}
$imge1 = addslashes(file_get_contents($_FILES['photo1']['tmp_name']));
$imge2 = addslashes(file_get_contents($_FILES['photo2']['tmp_name']));
if (!mysql_query("INSERT INTO forSale VALUES ('', '$sname', '$email', '$title', '$description', '$imge1', '$imge2')")) {
die(mysql_error());
echo("help");
}
mysql_close();
?>
ありがとう