Hi, I wanted to tell you that I want to do an Insert but check if there is a value in a column of the table before doing it, if it is an update only in the value of the column of the same.
I pass the code to you as I have it:
if(in_array($type, array('gif', 'jpg', 'jpeg', 'png', 'php'))) {
if (!file_exists($carpeta)) {
mkdir($carpeta, 0777, true);
}
if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
if(move_uploaded_file($_FILES['userImage']['tmp_name'], $url)) {
// AHORA TENDRIA q verrificar si existe el nombre del archivo en
//la TABLA ARCHIVOS y hago un update a la fechamod del mismo/
$cnombre= "SELECT idarchivo,nombre FROM archivos WHERE nombre = '$nombre'
AND idpersona = '$idpersona' AND idcategoria = '$idcategoria' AND idcarpeta
= '$idcarpeta'";
if($conn->query($cnombre) === TRUE) {
$sql="UPDATE archivos set nombre='$nombre'
where idarchivo='$row[idarchivo]'";}else{
// sino existe lo inserto
$sql = "INSERT INTO archivos
(idpersona,idcategoria,idcarpeta,nombre,url,tipo,tama,fechamod,fecha,estado)
VALUES
('$idpersona','$idcategoria','$idcarpeta','$nombre',
'$url','$type','$tama','$fechamod','$fecha','$estado')";
if($conn->query($sql) === TRUE) {
$valid['success'] = true;
$valid['messages'] = "Successfully Uploaded";
}
else {
$valid['success'] = false;
$valid['messages'] = "Error while uploading";
}
$conn->close();
}
else {
$valid['success'] = false;
$valid['messages'] = "Error while uploading";
}
}
}
echo json_encode($valid);
// upload the file
}
I'm still loading another record ... Well, if someone can give me a solution I'm grateful for. I hope the question is understood. Greetings to the whole community!