Jump to content

matthewhaworth

Members
  • Posts

    234
  • Joined

  • Last visited

    Never

Everything posted by matthewhaworth

  1. It just doesn't want to give me an error message any more.. I realised there was a problem with the SQL, I wasn't passing it 'auth'. I put little echo 'Im here'; markers throughout my code and it follows the method through thoroughly... but just doesn't but the information into the db
  2. Okay basically I'm just testing my register method in my user.class. Here is my user.class (I am a relatively new PHP programmer so please excuse my bad coding? I lose confidence very easily lol) <?php class user { // Database object . private $_db; // Report object. private $_report; // User details. private $_details = array(); // User authority. private $_auth = 0; function __construct($db, $report) { $this->_db = $db; $this->_report = $report; // Set variables if necessary. if($this->checkAuthority()) { $this->_details = $_SESSION['x']; $this->_auth = $_SESSION['auth']; } else { $this->_auth = 0; } } private function checkAuthority() { if(isset($_SESSION['auth'])) { if($_SESSION['auth'] == 1 || $_SESSION['auth'] == 2) { return true; } else { return false; } } } public function logout() { unset($_SESSION['x']); if($_SESSION['x'] == NULL) { $this->_report->addNote('Logout successful'); } else { $this->_report->addError('Logout unsuccessful'); } } public function register($details,$auth = 1) { if(!is_array($details)) { $this->_report->addError('Parameter passed incorrectly.'); return false; } // Clean variables. // Notice the & means it's a reference, not a copy. foreach($details as $k=>&$v) { $v = $this->_db->clean($v); if($v == NULL || $v == "") { $this->_report->addError('Field ' . $k . ' is missing.'); } } // Hash password with MD5. $details['password'] = md5($details['password']); // Make the joindate, and also make it comply to MySQL's format. $details['joindate'] = time(); /* Making the birthdate This will require three drop down boxes: birthday, birthmonth and birthyear. */ $details['birthdate'] = strtotime($details['birthmonth'] . '/' . $details['birthday'] . '/' . $details['birthyear']); unset($details['birthday']); unset($details['birthmonth']); unset($details['birthyear']); // Add 'auth' to the array. $details['auth'] = $auth; // Create SQL to insert data. $sql = "INSERT INTO members ('email', 'password', 'username', 'joindate', 'birthdate', 'auth') VALUES("; $sql .= "'" . $details['email'] . "', "; $sql .= "'" . $details['password'] . "', "; $sql .= "'" . $details['username'] . "', "; $sql .= "'" . $details['joindate'] . "', "; $sql .= "'" . $details['birthdate'] . "');"; // ..do so. $qry = $this->_db->query($sql); // Log user in. $this->login($details['email'], $details['password']); return true; } public function login($email, $password) { if(!($email && $password)) { return false; } // Clean up variables. // May have a validation class later in the game : - ). $email = $this->_db->clean($email); $password = $this->_db->clean($password); $password = md5($password); // Create SQL to find member information. $sql = "SELECT * FROM members WHERE email = '" . $email . "';"; // Query the database with the SQL. $qry = $this->_db->query($sql); // Check to see if the user exists. if($this->_db->numrows() < 1) { // The user doesn't exist. $this->_report->addError('User does not exist'); return false; } // Load user details. $this->_details = $this->_db->fetch($qry); // Check if the user's password is correct. if($this->_details['password'] != $password) { // The user's password is incorrect $this->_report->addError('Incorrect password'); return false; } // Unset the password because it's not safe to have it in the enviroment // longer than it is needed. unset($this->_details['password']); // Create sessions. // Loop through every key and value assigning it to a session, except password and auth. // $_SESSION['x'] is the array in which all of the user details are stored. foreach($this->_details as $k=>$v) { if($k != 'auth') { $_SESSION['x'][$k] = $v; } } // Set authority digit. $_SESSION['auth'] = $this->_details['auth']; // /* $this->_report->addNote($_SESSION['auth']); // */ return true; } } ?> Here's where I call it <?php require("inc.php"); $man = array ( 'email' => 'matthewhaworth@hotmail.com', 'password' => 'moe', 'username' => 'matthewhaworth', 'birthday' => '23', 'birthmonth' => '08', 'birthyear' => '1990'); $user->register($man); $report->debug(); ?>
  3. I have all my errors turned on in php.ini and i even have error_reporting(E_ALL); in my script, however it only displays an error message on the odd refresh of the page, now and then.. does my php have attitude or is this fixable? lol
  4. That has to be the most fantastically and elaborately worded first or second post that I have ever seen lol. Thanks a lot for your help Steve, it has cleared things up fantastically, you must really know your stuff.
  5. I am quite thorough when it comes to programming, I always want to do things the most quick, efficient and 'well-respected' ways. Often I come up with my own ideas but not nearly often enough... My current problem is, what is the correct way to go about creating a user class and how does it integrate with session variables? I mean, do I pass the user object within the sessions? Or do I load the user object from the session variables on every page? Should I have a separate class that deals with sessions? Or should I just leave them open? Thank you.
  6. Omg. No. Thanks a lot, you've been great. Oh it's embarrassing. have to rush off now anyway lol.
  7. Here is: "db.class.php" <?php class db { private $_db; private $_report; private $_querycount = 0; private $_tempquery; function __constructor($report, $db, $user, $pass, $host = 'localhost') { $this->_db = new mysqli($host, $user, $pass, $db); $this->_report = $report; if ($this->_db->connect_errno) { $this->_report->addError('Database connection failed: ' . $this->_db->connect_errno); } else { $this->_report->addNote('Database connection successful.'); } } function query($sql) { if ($this->_tempquery = $this->_db->query($sql)) { $this->_report->addNote('Query successful.'); $this->_querycount++; return $qry; } else { $this->_report->addError('Query unsuccessful: <br />' . $sql . '<br />' . $this->_db->connect_error); } } function numrows($qry = NULL) { if($qry == NULL) { $qry = $this->_tempquery; } return $qry->num_rows; } function fetch($qry = NULL) { if($qry == NULL) { $qry = $this->_tempquery; } return $qry->fetch_assoc(); } function multifetch($qry = NULL) { if($qry == NULL) { $qry = $this->_tempquery; } $rows = array(); while ($row = $qry->fetch_assoc()) { $rows[] = $row; } return $rows; } } ?> Here is: "report.class.php" <?php class report { private $_userinfo = array(); private $_errors = array(); private $_notes = array(); public function addError($err) { $this->_errors[] = $err; } public function addNote($note) { $this->_notes[] = $note; } public function debug() { $t = "<div name='debug'>"; foreach($this->_userinfo as $userinfo) { $t .= $userinfo; $t .= "<br />"; } foreach($this->_errors as $errors) { $t .= $errors; $t .= "<br />"; } foreach($this->_notes as $notes) $t .= $notes; $t .= "</div>"; return $t; } } ?> Here is: "inc.php" <?php require("report.class.php"); require("db.class.php"); $report = new report(); $db = new db($report, "forum", "root", "passwordlol"); ?> Thank you a LOT for your help so far : ].
  8. Nope : [. Edit: If anybody else read my other thread and has realised that I have corrected the error I had with default parameters incorrectly.. don't worry, I realise it should be "if ($qry == NULL)" now lol.
  9. I retract my previous statement, it's still not working with the same error message. <?php //connect to server require("inc.php"); //gather the topics $get_topics_sql = "SELECT topic_id, topic_title, DATE_FORMAT(topic_create_time, '%b %e %Y at %r') aS fmt_topic_create_time, topic_owner FROM forum_topics ORDER BY topic_create_time DESC"; $get_topics_res = $db->query($get_topics_sql); ?> Here is inc.php <?php require("report.class.php"); require("db.class.php"); $report = new report(); $db = new db($report, "forum", "root", "passwordlol"); ?>
  10. Aye. I probably read the php.net function definition for the procedural one, without paying much attention. I think they've done a really poor job with the mysqli documentation.
  11. Very good point, it should be $this->$_db. Edit: No, it shouldn't lol, it doesn't need a link parameter, s'me being stupid. The problem seems to be fixed now. However, I'm still getting nothing but white (with errors turned on : P) but that's another problem I should be able to handle myself. Thank you : ].
  12. <?php class db { private $_db; private $_report; private $_querycount = 0; private $_tempquery; function __constructor($report, $db, $user, $pass, $host = 'localhost') { $this->_db = new mysqli($host, $user, $pass, $db); if ($this->_db->connect_errno) { $this->_report->addError('Database connection failed: ' . $this->_db->connect_errno); } else { $this->_report->addNote('Database connection successful.'); } } function query($sql) { if ($this->_tempquery = $this->_db->query($_db, $sql)) { $this->_report->addNote('Query successful.'); $this->_querycount++; return $qry; } else { $this->_report->addError('Query unsuccessful: <br />' . $sql . '<br />' . $this->_db->connect_error); } } function numrows($qry = NULL) { if($qry) { $qry = $this->_tempquery; } return $qry->num_rows; } function fetch($qry = NULL) { if($qry) { $qry = $this->_tempquery; } return $qry->fetch_assoc(); } function multifetch($qry = NULL) { if($qry) { $qry = $this->_tempquery; } $rows = array(); while ($row = $qry->fetch_assoc()) { $rows[] = $row; } return $rows; } } ?> Fatal error: Call to a member function query() on a non-object in C:\apache2triad\htdocs\forum\db.class.php on line 21 if ($this->_tempquery = $this->_db->query($_db, $sql)) { That is the line in question if you can't be bothered counting lol.
  13. function numrows($qry = $this->_tempquery) { return $qry->num_rows; } Parse error: syntax error, unexpected T_VARIABLE in C:\apache2triad\htdocs\forum\db.class.php on line 30 Line 30 is the first line in the code I have shown you. I have looked behind it and there are definitely no missing ';'. I think the problem is setting a variable as the default parameter.. maybe it has to be $qry = "..", but I'll be really annoyed if it does, because it messes up my whole script concept.
  14. With <br />. I just clicked your link and it loaded a couple..
  15. This looks too like Facebook - the logo is almost exactly the same. This has been done far too many times. "Fundobox.com is more than an online community that connects people through a network of friends via music, videos, chit-chat & pictures. " How is it? I don't like that I can't browse through people without being registered.
  16. There are far too many gradients. This is something I notice a lot in websites.. they over use gradients and I think it just begins to look 'too shiny' thus 'tacky'. Also, staying "PHP Zone UK" and limiting something that's worldwide to one country? There's no point in doing that.. I mean, obviously people from other countries would still go on it regardless, it's just.. I don't know, it implies there is a PHP Zone USA or something.. and makes it sound like a website chain which is pretentious and annoys me.
  17. I'm sorry, but I'm sick of seeing this 'Portal' style design and I have to agree with the others.. I dislike drop down menus. My unique criticism is, however [do not create a website unless you have content to put on it]. That is a rule I VERY much follow.. your website, has links and a forum, both of which has little input from yourself in terms of unique content. It is unique content that makes a website. Your website concept has been done, many, many times before.. think about the website that you're on now for example. I like the integration of the main login with the forum login. That's all I can say. Good luck :].
  18. It works for me, just replace the \n with <br />.. lol, i keep making stupid mistakes like that.. i have PHP flu lol.
  19. <?php // Connect to MySQL. if (!mysql_connect("localhost", "username", "password")) { exit('Connection unsuccessful' . mysql_error()); } // Connect to the database. if (!mysql_select_db("database")) { exit('Could not connect to database' . mysql_error()); } // Query the database for records with zip = to what the user posted. $result = mysql_query("SELECT * FROM `air09` WHERE zip = '" . $_POST["search"] . "' ORDER BY `air09`.`zip` ASC LIMIT 0, 30") or exit('Error: '.mysql_error()); // Output the results of the query. while($r = mysql_fetch_array($result)) { echo $r["cert_no"]; echo '<br />'; echo $r["first_name"]; echo ' '; echo $r["last_name"]; echo '<br />'; echo $r["address"]; echo '<br />'; echo $r["address_2"]; echo '<br />'; echo $r["city"]; echo '<br />'; echo $r["state"]; echo '<br />'; echo $r["zip"]; echo '<br />'; } ?> Here, I saw what you were trying to do.. with the query.. (I think).. so I added it. Also, I improved what others said was wrong.
  20. There is no line 74.. have you posted the whole code? Plus, please use [ code ] tags when posting php, click the '#' in the Post Reply toolbox. Also <?php echo ' '; ?> Will not move the text onto a new line lol. Use br as in the code I showed you. Edit: Well, actually, apparently it will.. lol I learn something new every day.
  21. <?php if (!(mysql_connect("localhost", "username", "password"))) { exit('Connection unsuccessful' . mysql_error()); } if (!(mysql_select_db("database"))) { exit('Could not connect to database' . mysql_error()); } $search = $_POST["search"]; // I don't know where you use this? //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM `air09` ORDER BY `air09`.`zip` ASC LIMIT 0, 30") or exit('Error: '.mysql_error()); //grab all the content while($r = mysql_fetch_array($result)) { echo $r["cert_no"]; echo '<br />'; echo $r["first_name"]; echo ' '; echo $r["last_name"]; echo '<br />'; echo $r["address"]; echo '<br />'; echo $r["address_2"]; echo '<br />'; echo $r["city"]; echo '<br />'; echo $r["state"]; echo '<br />'; echo $r["zip"]; } ?> Try that.. Edit: I've updated this a few times.. I've taken into account craygo's post below.
  22. mysql_error() not mysql_error () I'm still looking though, just in case.. btw.. you need to put more <br />'s in your echo, pressing enter doesn't actually put them on the lower line.. <?php //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost", "username", "password"); //select which database you want to edit mysql_select_db("database"); $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM `air09` ORDER BY `air09`.`zip` ASC LIMIT 0 , 30 ") or die('Error: '.mysql_error()); //grab all the content while($r = mysql_fetch_array($result)) { echo $r["Cert No"] . '<br />'; echo $r["First Name"]. ' '; echo $r["Last Name"] . '<br />'; echo $r["Address"] . '<br />'; echo $r["Address 2"] . '<br />'; echo $r["City"] . '<br />'; echo $r["State"] . '<br />'; echo $r["Zip"]; } ?> Try that. I've just realised that your DB doesn't match up with your array. Cert No = Cert_No
  23. But that's days since 1970, not exactly what the OP wants Tbh, I foolishly never looked at what the function he wanted actually did and just took a guess lol..
×
×
  • 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.