I’m working on validating an image submission form with jQuery. I need it to check if there is an instance of the given submission url in the database to reduce reposts. I used the following code:
$("#submit_form").validate({
rules: {
right_form_title: {
required: true,
maxlength: 105
},
right_form_url: {
required: true,
image: true,
gif: true,
remote: "/~lyons/imagecheck.php"
}
},
messages: {
right_form_url: {
remote: "That image has already been submitted under that URL."
}
}
});
});
Imagecheck.php:
<?php
//Database Information
$dbhost = "";
$dbname = "";
$dbuser = "";
$dbpass = "";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$title = mysql_real_escape_string($right_form_url);
$query = "SELECT filename FROM images WHERE filename='$title';";
$res = mysql_query($query);
if (mysql_num_rows($res) > 0) {
return false;
} else {
return true;
}
echo json_encode($output);
?>
The problem is that now, no matter what, everything comes back as having been submitted before. What is wrong with this? I have literally no clue after looking for awhile.
When you do return true and return false, these values are only in the php environment (server side). Thus, the value that you get in jquery is the
This will always evaluate to false.