我正在使用jQuery验证图像提交表单。我需要它来检查数据库中是否存在给定提交URL的实例,以减少重新发布。我使用以下代码:

$("#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);


?>


现在的问题是,无论如何,一切都会像以前一样提交。这有什么问题?寻找了一段时间后,我几乎没有任何线索。

最佳答案

当您返回true和false时,这些值仅在php环境中(服务器端)。因此,您在jquery中获得的值是

echo json_encode($output)


这将始终为false。

关于jquery - jQuery验证-使用远程查看MySQL数据库中是否存在某些实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8439775/

10-12 12:18
查看更多