Jump to content

ch1326

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Everything posted by ch1326

  1. Thanks a lot everyone for answering my question. That helped me a lot to move to the next step of being a web developer
  2. This might be silly questions but I desperately want to know….. - Do you need to use Object Oriented PHP all the time when you work??? - Do you have to know Design Pattern for your work? - Do you think people who only how to use Function in PHP could get jobs as PHP developers? - In order to get a web developer job, what else should I know ? Please no offense!!
  3. You are AWESOME, Nightslyr!!!!! Thank you so much
  4. Hi, everyone. I'm having a problem with getting the result from my php code. <?php class Mysql{ private $host; private $user; private $pass; private $db; public function __construct(){ $this->host = "localhost"; $this->user = "root"; $this->pass = "password"; $this->db = "person"; $this->conn(); } private function conn(){ $conn = mysql_connect($this->host, $this->user, $this->pass); if(!$conn){ mysql_error(); }else{ mysql_select_db($this->db, $conn); } } public function query($sql){ $result = mysql_query($sql); return $result; } public function fetch_array($result){ return mysql_fetch_array($result); } public function num_rows($result){ return mysql_num_rows($result); } } $db = new Mysql(); /******************************************************************************************/ class Person{ public $id; public $name; public function show_all(){ return $this->by_sql("SELECT * FROM USERS"); } public function show_by_id($id){ return $this->by_sql("SELECT * FROM USERS WHERE id = {$id} LIMIT 1"); } public function show_by_name($n){ return $this->by_sql("SELECT * FROM USERS WHERE name = {$n}"); } private function by_sql($sql){ global $db; $result = $db->query($sql); $arr = array(); while ($r = $db->fetch_array($result)){ $arr[] = $this->initiate($r); } return $arr; } private function initiate($r){ $obj = new self; foreach ($r as $att=>$val){ $obj->$att = $val; } return $obj; } } ?> <?php //phpinfo(); require_once("obj.php"); $user = new Person(); echo $user->show_by_id(1); ?>
  5. Can't figure it out what error is. need help ASAP <?php session_start(); include ("forum.inc"); $links = "<a href = 'main.php'>Click here to proceed to the main page</a><br /><br /><a href = 'enter.php'>Click here to log out.</a>"; if ($user && $pass){ if ($logged_in_user = $user){ setup_page("Already logged in", "Whoops"); l echo "{$user}, You are already logged in. <BR /><BR />"; echo $links; exit; } doConnect() $result = mysql_query("SELECT * FROM user where name = '{$user}' AND password = {$pass} "); if (!$result){ fail("database query failed, login page", true); } if (mysql_num_rows($result)>0){ $record = mysql_fetch_assoc($result); $logged_userID = $record["userID"]; $_SESSION["logged_userID"]; $logged_in_user = $user; $_SESSION["logged_in_user"]; if ($record["mod"]){ $logged_as_mod = true; $_SESSION["logged_as_mod"]; } setup_page("Welcome","Welcome"); echo $links; exit; }else { setup_page("Invalid","Invalid login"); echo "That username-password combination does not appear to match our records. Pleas try again. <BR/><BR/>"; } elseif($user || $pass){ setup_page("Invalid","Invalid login"); echo "Please fill in both fields.<BR/><BR/>"; } else{ setup_page("Login","Login"); echo "Please enter your detail to log in"; } } ?> <form method = 'POST' ACTION = 'login.php'> Your username: <input type = 'text' name = 'user' MAXLENGTH = '20' SIZE = '10'><BR> Your password: <input type = 'password' name = 'password' MAXLENGTH = '10' SIZE = '10'><BR> <input type = 'submit' value = 'Login'> </form> </body> </html> Cheers
  6. To all PHP developers. I believe some of you guys are working as PHP developers and some might use other scripting languages with PHP to support websites. My question is.... Is OOP in PHP necessary for real world business??? Do u really use them when you start creating some websites (small to medium) ? if so, how complex of OOP need to be made in PHP ???? Thanks for answering all my questions ....
  7. Hi everyone I need help with my "public fetch()", which is not working. seem to be something wrong with arrays Here is the code <?php class MYSQL { private $user = "root"; private $pass = "password"; private $host = "localhost"; private $db = "userlist"; public function __construct(){ $this->user; $this->pass; $this->host; $this->db; $this->connDB(); } private function connDB(){ $conn = mysql_connect($this->host, $this->user, $this->pass); if (!$conn){ print(mysql_error()); echo "<BR/> <BR/> Please check your login again. <BR /><BR />"; }else{ return mysql_select_db($this->db, $conn); } } public function fetch($tName){ $sql = "select * from $tName"; $result = mysql_query($sql); return mysql_fetch_array($result); } public function addData($tName, $field, $val){ $sql = "insert into $tName ($field) values ($val)"; return mysql_query($sql); } } ?> Thank again for the help
  8. Got some errors from this code. need help please <?php class MYSQL { var $host = "localhost"; var $user = "root"; var $pass = "password"; var $db = "userlist"; function __construct($host, $user, $pass, $db){ $this->host = $host; $this->user = $user; $this->pass = $pass; $this->db = $db; } public function query($sql){ $this->connDB(); $result = mysql_query($sql); return fetchArray($result); } public function fetchArray($result){ while ($row = mysql_fetch_array($result) ){ echo "Name is ". $row["name"]; } } public function connDB () { $conn = mysql_connect($this->host, $this->user, $this->pass); mysql_select_db($this->db, $conn); } } $example = new MYSQL(); echo $example->query("select * from user"); ?>
  9. Thank so much MasterACE14 Problem solved now
  10. I have 100 data in tbl_page table. I would like to display 20 data on each page and when I click next, it supposes to display next 20 data. if I click previous, it supposes to go back to the last 20 data. but it does not work. Cheers
  11. how about trying if(mysql_num_rows($chk_user) > 0) { $errorMsg .= AFF_SI_USEREXISTS.'<br>'; $_POST['ausername'] = '<font color = 'red'>Name Already Taken, Try Another</font>'; } I hope it will work
  12. Hi everyone, I am getting with clicks of "next" and "previous". when I click eigther next or previous it does not seem to be working correctly. Please help! Thank u everyone <html> <head> <title>Page</title> <style type = 'text/css'> A:link {font-family:Arial, Helvetica, sans-serif; font-size:10pt; text-decoration:none; color:blue} A:visited {font-family:Arial, Helvetica, sans-serif; font-size:10pt; text-decoration:none; color:blue} A:hover {font-family:Arial, Helvetica, sans-serif; 10pt; font-size:text-decoration:none; color:red} .small{font-family:Arial, Helvetica, sans-serif; font-size:10pt; text-decoration:none} </style> </head> <body bgcolor = '#F1F1F1'> <p class = 'small'> <?php include "phpConfig.php"; $conn = mysql_connect($ServerName, $UserName, $UserPassword); if (!$conn) { die("Cannot connect to server<BR>"); } mysql_select_db ($DatabaseName, $conn) or die ("$DatabaseName database not found<BR>"); $strSQL = "select * from tbl_page"; $Per_Page = 20; if (!$Page) { $Page = 1; } $Prev_Page = $Page - 1; $Next_Page = $Page + 1; $result = mysql_query($strSQL); $Page_start = ($Per_Page*$Page)- $Per_Page; $Num_Rows = mysql_num_rows($result); if ($Num_Rows<=$Per_Page) { $Num_Pages=1; } elseif ( ($Num_Rows%$Per_Page) == 0 ) { $Num_Pages = ($Num_Rows/$Per_Page); } else { $Num_Pages = ($Num_Rows/$Per_Page)+1; } $Num_Pages = (int) $Num_Pages; if ( ($Page>$Num_Pages) || ($Page<0) ) { print "Number of $Page is more than $Num_Pages"; } $strSQL = "select * from tbl_page limit $Page_start, $Per_Page"; $result = mysql_query($strSQL); while ( $rs = mysql_fetch_array ($result) ) { echo "$rs[iD]<br>\n"; } ?> <p class = 'small' > Total <b><?php echo $Num_Rows;?></b> numbers and <b><?php echo $Num_Pages; ?></b> pages: <?php if (isset ($Prev_Page) ) { echo "<a href='$PHP_SELF?Page=$Prev_Page'><<previous</a>"; } for ($i=1; $i<=$Num_Pages;$i++) { if (!$Page) { echo "[<a href = '$PHP_SELF?Page=$i'>$i</a>]"; } else { echo "<b>[$i]</b>"; } } if ($Page != $Num_Pages) { echo "<a href = '$PHP_SELF?Page=$Next_Page'>Next>></a>"; } mysql_close($conn); ?> </body> </html>
  13. Have you connected and selected the database before adding data? mysql_connect(); mysql_select_db(); and don't forget mysql_query(); I hope this might help.
  14. hi everyone, I need some help with this code. everytime when i push F5, it keep showing 1 only. what i want is, when I put F5 everytime the value would +1 <?php if (isset ($_COOKIE["numCounter"]) ){ $_COOKIE["numCount"]++; setcookie("numCount", $_COOKIE["numCount"]); } else { setcookie("numCount",1); } echo $_COOKIE["numCount"]; ?>
  15. Many thanks for all of u !!!! PROBLEM SOLVED !!!! THANK AGAIN
  16. Hi everyone , I am having problem with date function. I would like to display year, month, date seperately with my $dt variable but seem everything is not correct. Please help !!!!! Thank u <?php $dt = date("y/m/d"); echo $dt(y); echo $dt(m); echo $dt(d); ?>
  17. Anyone have any idea, how could i find PHP exercises ? Because i would like to develop my PHP skill Thank you
  18. class MySQL { var $host ; var $dbUser ; var $dbPass ; var $dbName ; var $dbConn ; var $dbconnectError ; function MySQL ( $host , $dbUser , $dbPass , $dbName ) { $this->host = $host ; $this->dbUser = $dbUser ; $this->dbPass = $dbPass ; $this->dbName = $dbName ; $this->connectToDb() ; } function connectToDB() { $this->dbConn = @mysql_connect($this->host , $this->dbUser , $this->dbPass ) ; if ( !$this->dbConn ) { trigger_error ('could not connect to server' ) ; $this->dbconnectError = true ; } else if (!@mysql_select_db ( $this->dbName , $this->dbConn) ) { trigger_error ('could not select database' ) ; $this->dbconnectError = true ; } } function isError() { if ( $this->dbconnectError ) { return true ; } $error = mysql_error ( $this->dbConn ) ; if (empty ($error)) { return false ; } else { return true ; } } function query ( $sql ) { if (!$queryResource = mysql_query ( $sql , $this->dbConn )) { trigger_error ( 'Query Failed: ' . mysql_error ($this->dbConn ) . ' SQL: ' . $sql ) ; } return new MySQLResult( $this, $queryResource ) ; } } class MySQLResult { var $mysql ; var $query ; function MYSQLResult ( &$mysql , $query ) { $this->mysql = &$mysql ; $this->query = $query ; } function size() { return mysql_num_rows($this->query) ; } function fetch() { if ( $row = mysql_fetch_array ( $this->query , MYSQL_ASSOC )) { return $row ; } else if ( $this->size() > 0 ) { mysql_data_seek ( $this->query , 0 ) ; return false ; } else { return false ; } } function isError() { return $this->mysql->isError() ; } } ?> Hope this will help.
  19. This might be help. <?php function cows($noise) { if ($noise == moo) { echo $say = "Hi Mr. Cow"; } else { echo $say = "Your no Cow fool!"; } } cows('moo'); ?>
  20. Hi, All Anyone has any idea of how to create a payment online website by using PHP ? Thanks
  21. Hi, All. I having some difficulties of Clicking Back to previous page. I have created a register page and signed in successfully but when I clicked "Back" to previous page, I have discovered my web browser has shown "Page not found". Anyone has any idea??? please help!!!!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.