How about, I'm starting with ajax and even though I've searched, I can not find the error, I want to post a picture but it does not work, could you help me? I leave the code, thank you already.
I think the error is in the ajax part, but it does not work for me.
index.html
<!doctype html>
<html lang="es">
<head>
<meta charset="UTF-8">
<script src="js/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="js/mijs.js"></script>
<title>inicio</title>
</head>
<body>
<div class="row">
<div class="col-sm-4"> </div>
<div class="col-sm-4">
<div class="jumbotron">
<form id="frm" enctype="multipart/form-data">
<div class="form-group">
<input type="text" class="form-control" placeholder="Nombre" id="nombre" name="nombre">
</div>
<div class="form-group">
<label class="btn btn-primary" for="my-file-selector">
<input id="my-file-selector" type="file" style="display:none" name="img"
onchange="$('#upload-file-info').html(this.files[0].name)">
Subir archivo
</label>
<span class='label label-info' id="upload-file-info"></span>
</div>
<div class="form-group">
<input id="guardar" type="submit" value="ENVIAR" class="btn btn-primary">
</div>
</form>
</div>
</div>
<div id="resp" class="col-sm-4">Hola </div>
</div>
<script>
$(document).ready(function(){
$("#guardar").click(function(){
$.ajax({
url:'mandar.php',
type:'POST',
data:$('#frm').serialize()
,success:function(){
alert('OK');
}
});
});
});
</script>
</body>
</html>
mandar.php
<?php
$nombre = $_POST['nombre'];
$img = $_FILES['img']['name'];
$ruta = $_FILES['img']['tmp_name'];
$destino = "fotos/".$img;
if($_FILES['img']['size'] > 500000){
echo 'El archivo es muy grande!!';
die('sube un archivo más pequeño');
}
copy($ruta, $destino);
include './db_const.php';
$con = new mysqli($host, $username, $passwd, $dbname);
if(!$con){
echo 'ERROR DE CONEXION',$con->connect_errno;
die('ERROR');
}
$qy = "insert into alumnos (nombre,imagen) values('{$nombre}','{$destino}');";
if($con->query($qy)){
echo 'Todo bien';
}
else{
echo 'ERROR';
}