-3
   <?php

   if (isset($_COOKIE["username"])) {

$listType = $_POST['listType'];
$uid = $_COOKIE['username'];
$con = mysql_connect('localhost','xxxx','xxxx');
if(!$con)
{
        die("Could not connect: " . mysql_error());
}

$db = mysql_select_db('xxx');

$getUseridquery = mysql_query("SELECT * FROM user WHERE membername='".$uid."'") or die("error1" .mysql_error());
while ($row = mysql_fetch_array($getUseridquery)or die("error11" .mysql_error())) {
    $user_id = $row['uid'];
    typeHandler($listType, $user_id);
}

   } else {
       //something wrong
       return failure;
   }

   function typeHandler($type, $id) {
       if ($type == 'sub') {
        //get the list of subscibers if there's any
        $getSubscribe_query = mysql_query("SELECT target_id FROM subscribes WHERE owner_id='" . $id . "'") or die("error2".mysql_error());
           $subArray = mysql_fetch_array($getSubscribe_query);
           $rowcount = mysql_num_rows($getSubscribe_query) or die("error22".mysql_error());
           if ($rowcount > 0) {
            makeSubList($subArray, $id, TRUE);
           } else {
            makeSubList($subArray, $id, FALSE);
           }

       }

       if ($type == '') {

       }

   }

   function makeSubList($iArray, $id, $hasSub) {

if ($hasSub = TRUE) {
    //if user subscribed to others
    $responseArray = array();
    for ($a = 0; $a <= count($iArray); $a++) {
        makeListEntry($iArray[$a], $responseArray);
    }

    //add owner's scene
    makeListEntry($id, $responseArray);
    return $responseArray;
} else {
    //just add ower to the list
    $responseArray = array();
    makeListEntry($id, $responseArray);
    return $responseArray;
}

   }

   function makeListEntry($user_id, $responseArray) {

//scene count
$getSceneInfo = mysql_query("SELECT * FROM scene WHERE uid='" . $user_id."'") or die("error3".mysql_error());
$sceneCount = mysql_num_rows($getSubscribe_query)or die("error34".mysql_error());

//latest scene
$getLatestScene = mysql_query("SELECT * FROM scene WHERE uid='" . $user_id . "' ORDER BY time_created DESC LIMIT 1") or die("error4".mysql_error());
while($row = mysql_fetch_array($getLatestScene) or die("error44".mysql_error())){
    $title = $row['title'];
    $time = $row['time_created'];
}


//count follower
$getFollower = mysql_query("SELECT * FROM subscribes WHERE target_id='" . $user_id . "'") or die("error5".mysql_error());
$followerCount = mysql_num_rows($getFollower) or die("error54".mysql_error());

//get subscriber info
$getSubInfo = mysql_query("SELECT * FROM user WHERE uid='" . $user_id . "'") or die("error6".mysql_error());
while ($row = mysql_fetch_array($getSubInfo)or die("error66".mysql_error())){
    $dp = $row['dp_file'];
    $name = $row['name'];
}

//store data response to array
$response = array('name' => $name, 'dp' => $dp, 'title' => $title, 'uploadtime' => $time, 'scenecount' => $sceneCount, 'followercount' => $followerCount);
//store response to page
$responseArray . array_push($response);
   }

   ?>

基本的に、mySQL のさまざまなテーブルから情報を取得し、これらのデータを配列に格納して、AJAX を使用して他の JavaScript ファイルに渡すことができるようにしようとしていました。

これらのコードは、どういうわけか、エラー メッセージのない MySQL エラー ボックスをスローします。

各エラー メッセージを識別するために追加の文字列を割り当てようとしましたが、私が書いた文字列のみが表示され、エラーは解決されません。

PS私はPhpMyAdminを使用しています。

助けてください。

4

2 に答える 2

2

これが唯一の問題かどうかはわかりませんが、フェッチ中にエラーをチェックすることはできません。行が残っていない場合にmysql_fetch_*()戻りますが、それはエラー状態ではありません:FALSE

// Don't do this!
// If no rows are found, or as soon as you have fetched all rows,
// it will exit with a bogus error.
while($row = mysql_fetch_array($getLatestScene) or die("error44".mysql_error())){}

// Instead check for errors first, then just loop:
$getLatestScene = mysql_query("SELECT * FROM scene WHERE uid='" . $user_id . "' ORDER BY time_created DESC LIMIT 1") or die("error4".mysql_error());
while($row = mysql_fetch_array($getLatestScene)){}

注: スクリプトは SQL インジェクションに対して脆弱です。入力値をフィルタリングします。

$listType = mysql_real_escape_string($_POST['listType']);
$uid = mysql_real_escape_string($_COOKIE['username']);

しかし..ユーザー名をに保存するのは悪い考え$_COOKIEです。代わりに、その値を に保存する必要があります$_SESSION。どのユーザーも、Cookie を偽造するだけで、他のユーザーになりすますことができます。どこに電話しているかはわかりませんsetcookie()が、そうすべきではありません。代わりに次のようにします。

// at start of script
session_start();
// Later, store the user in $_SESSION
$_SESSION['username'] = 'the username';
于 2012-09-04T14:55:19.880 に答える
0

AJAX デバッグの目的で、AJAX-Module は

die(JSON_encode("mysql_error",mysql_error()))

デバッグ時間を簡単にします。

于 2012-09-04T14:55:41.693 に答える