如果var为空则需要退出函数并使ajax显示错误PHP / AJAX

Okay, so I have an AJAX function that sends data to the .php file, which processes it (simple as that):

$(document).on('click','#submit',function () {
    var title = $('#title_submit').val();
    var content = $('#content_submit').val();
    var image = $('#image_url').val();
    $.ajax({
        type: "POST",
        url: "../parts/add.php",
        data: {
            title: title,
            content: content,
            image: image
        },
        success: function (data) {
            redirect(); //a function that redirects to the main page
        }
    });
});

The content passes fine, and the function processes it. So, if there is no image ("image_url" field is empty) it simply ignores it and just adds the title and the content... But if there is an image it checks it's type (switch ($info) { case 'image/jpg':...) if none of them match:

default:
$new_name = "";
break;
}

and here's the hard part (for me):

if ($new_name == "") {
...//stop from executing and say "That ain't no image you be sendin'"; 
} else { //continue with adding an image to the folder and than creating a thumbnail of it...

I tried die() but if I entered something like "11111111111111111111111" into the Image URL input it entered "11111111111111111111111" into the database and outputed it instead of the image.

You are checking wrong way, its like assigning empty string to $name use == operator to check against empty string

if ($new_name == "") {