เอิ่มมม !! ช่วยเข้ามาดู Code ผมหน่อยครับทำไมมันไม่แสดงผล - -" [PHP function]

เริ่มโดย IOlIDIl, 15 กรกฎาคม 2012, 20:46:37

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

IOlIDIl

อย่าว่างู้นงี้เลยครับ

ไม่รู้จะบอกว่าไงดีก็ไม่ไม่แสดงผลออกมาอะครับ

นี้คือ code ฟั่งชั่น
<?php
session_start();

   class myDatabase {
      public function connect2database($strHost,$strDB,$strUser,$strPassword) {
      if ($objConnect = mysql_connect($strHost,$strUser,$strPassword)) {
       echo "Yess";
      } else {
         echo "555555";
      }
      mysql_query("SET NAMES TIS620");
      $this->DB = mysql_select_db($strDB);
      }
      public function QueryDB($strSQL) {
      $strSQL = mysql_query($strSQL);
      }
      public function insert2DB($strSQL) {
      
      }
      public function __destruct() {
         return @mysql_close($this->objConnect);
         }
   }
   
   
   class P_register {
      public $invalid = false;
      public function Checkfield($text,$pattern,$min,$max,$format = false) {
         if (strlen($text) >= 1 ) {
         if (strlen($text) >= $min and strlen($text) <= $max) {
         if ($format == false) {
            if (preg_match($pattern,$text)) {
                print "Your username is ok.";
               $this->invalid = true;
               } else {
                print "Wrong username format.";
               $this->invalid = false;
               }
               
               } elseif (ereg($pattern,$text)) {
               print "You Username is ok.";
               $this->invalid = true;
               } else {
               print "Wrong Username format.";
               $this->invalid = true;
               }
      
                              }
         } else {
          return "Blank !! You'd put your charater";
         }
   }
} // ปิดคลาส P_register
?>


ส่วนนี้คอนผมใช้อะครับ

$obj_r = new P_register();
   $P_Email = '/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*
  • [a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/';
                $obj_r->Checkfield('asd',$P_Email,6,50);
                $obj_c = new myDatabase();
                $obj_c->connect2database($Host,$DB,$username,$password);

    คือมันไม่มีอะไรแสดงผลขึ้นมาเลยครับ - -"

    ปล. ขอบคุณล่วงหน้าครับ (—/|\—)  (_/|\_)  :wanwan019:
ผมมันเกรียน โง่ บ้า ปัญญาอ่อน ขี้เกลียด บลาๆ

IOlIDIl

ผมมันเกรียน โง่ บ้า ปัญญาอ่อน ขี้เกลียด บลาๆ

vii

ที่ไม่แสดงผล มันไม่มี error เลยด้วยหรือเปล่าครับ?

ถ้าไม่มี error เลย และอยู่บน localhost หรือสามารถแก้ไข php.ini ได้ ให้ลองปรับตามนี้ครับ
http://www.okvee.net/articles/how-to-config-php-ini-for-development
ให้ทำสำหรับตอนที่พัฒนางานเท่านั้นนะครับ บนเว็บจริงไม่แนะนำให้ทำตามนี้

พอทำแล้ว restart apache แล้วเรียกดูใหม่ มันน่าจะมี error ก็ลองไล่แก้ดูครับ น่าจะทำได้แล้ว ถ้าไม่ได้ก็เอามาถามใหม่  :laugh:

dreamer

ผมทดลองcopy code แล้ว run ดู

รอบแรกพบว่ามันพิมพ์คำว่า Yess ออกมา

ก็เลยลองไล่สาเหตุว่าทำไม
$obj_r->Checkfield('asd',$P_Email,6,50);
จึงไม่พิมพ์อะไรออกมา พบว่า
มันไม่เข้าเงื่อนไขนี้ครับ

if (strlen($text) >= $min and strlen($text) <= $max) {

เพราะ $text มันยาวแค่ 3 แต่ $min มันเท่ากับ 6 ครับ

tctheworld


IOlIDIl

ขอบคุณมากครับ ได้แล้วครับ ฮืิฮิ

ซึ้งมากครับ :'(

ว่าแต่ debug คืออะไรหว่า ?????
ผมมันเกรียน โง่ บ้า ปัญญาอ่อน ขี้เกลียด บลาๆ

tctheworld

ถ้าเป็น php ก็ พวก display error น่ะครับ

ผมชอบเรียก debug น่ะครับ   :P