2012-04-23 80 views
0

我正在使用JQuery驗證插件。我得到了遠程函數與默認的PHP文件。JQuery驗證遠程和檢查數據庫PHP MySQL錯誤

我修改了PHP文件用我自己的版本,但MySQL是返回

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fastbluf/syatch/module/1.func.php on line 15 

我的PHP代碼如下。我的所有語法看起來都正確

<?php 
// Last Edited: 4/23/12 
$conn = mysql_connect('localhost','hidden','hidden') or die('Iam dying'); 
$rs = @mysql_select_db("hidden", $conn) or die("Err:Db"); 

$do = $_REQUEST['do']; 
$email= $_REQUEST['email']; 
$user= $_REQUEST['user']; 

function checkInfo($do,$email,$user){ 
    switch ($do) { 
     case 1: 
      $sql = "select * from User_Base where Email_Address = $email"; 
      $results = mysql_query($sql). mysql_error(); 
      $nResults = mysql_num_rows($results); 
      if ($nResults > 0) { 
       $valid="false"; 
      } else { 
       $valid="true"; 
      } 
     break; 

     case 2: 
     //not yet 
     break;  
    } 
    return $valid; 
} 
echo checkInfo($do,$email,$user); 
?> 

回答

2

的問題是,你要追加到你的結果,使其不再是一個有效的結果。

$results = mysql_query($sql). mysql_error(); 

嘗試改變這是這樣的:

$results = mysql_query($sql) or die(mysql_error()); 

您的查詢也應該改變引用的電子郵件地址,地址應該逃出來防止攻擊(SQL注入):

$email = mysql_real_escape_string($_REQUEST['email']); 
$sql = "select * from User_Base where Email_Address = '$email'"; 
+0

謝謝。很多..甚至沒有跟蹤真正的逃生字符串..病必須實現,無處不在現在.. – Ray 2012-04-23 19:09:27

+0

沒問題,很高興我可以幫助:) – Developer 2012-04-23 19:09:55

2

修復您的查詢

$sql = "select * from User_Base where Email_Address = '".$email."'";