Jump to content

3raser

Members
  • Posts

    815
  • Joined

  • Last visited

Everything posted by 3raser

  1. STILL NEED FEEDBACK > New Code: <?php /* * returnUsername is also used for checking if a user * is logged in, hence the name validation */ session_start(); class db { private $grab; public $return; public $username; public function connect($host, $user, $pass, $db) { mysql_connect($host, $user, $pass) or throw new Exception('Incorrect DB settings.'); mysql_select_db($db) or throw new Exception('DB connection failed.'); try { } catch (Exception $e) { echo 'EXCEPTION FOUND: ' $e->getMessage(); } } public function returnAmount($query) { $this->grab = mysql_fetch_assoc($query); if(mysql_num_rows($this->grab) < 1) { $this->return = "No results!"; return $this->return; } else { $this->return = mysql_num_rows($this->grab($query)); return $this->return; } } } class validation { public function returnUsername() { define('SESSION', $_SESSION['user']); if(!SESSION) { $username = null; return $username; } else { $username = SESSION; return $username; } } } ?>
  2. I don't really understand what you said here. I use a MySQL database. But are you suggesting to name it a database/XML file? Seems like XML is pointless over a database. But, other than that, I'm renaming my sql class to db. Hmm, I have absolutely no use for that in my current project. But I'll try to figure that in for the learning opportunity. Using google right now to search up some more information on exceptions, and hopefully find a good tutorial explaining them in detail. I don't know what you mean by this. Creating returnAmount allows me to use re-use code that I will most likely have used quite a few times. So this lets me cut down the time to type it all over again. As with the exceptions, I'm going to look up some more tutorials right away! Thats what returnAmount does. It allows me to re-use code that I will use quite a few times. For example, I tend to show how many people are registered, and how many people have submitted an application. I'll post the new code soon!
  3. It was a joke Ooh, thanks! And this wasn't a project, this was more of a test run. I'm starting my first ever actual OOP project. And I'd like some feedback, but this is currently the class_library.php: <?php /* * returnUsername is also used for checking if a user * is logged in, hence the name validation */ session_start(); class sql { private $grab; public $return; public $username; public function connect($host, $user, $pass, $db) { $error = array(); mysql_connect($host, $user, $pass) or $error[0] = 1; mysql_select_db($db) or $error[1] = 1; if(!(empty($error[0])) || !(empty($error[1]))) die("MySQL configuration is wrong!"); } public function returnAmount($query) { $this->grab = mysql_fetch_assoc($query); if(mysql_num_rows($this->grab) < 1) { $this->return = "No results!"; return $this->return; } else { $this->return = mysql_num_rows($this->grab($query)); return $this->return; } } } class validation { public function returnUsername() { define('SESSION', $_SESSION['user']); if(!SESSION) { $username = null; return $username; } else { $username = SESSION; return $username; } } } ?>
  4. No, no, no. I know how to do that. But is it possible to write certain information to equal certain variables? I've had a member on here give me the code to do something like this, but I never bothered to learn the code and study it. So I regret that. <.<
  5. Say I have an installation file, and they type in all their database information & click submit. How would I get that information to open up a file called config.php, and write to the $db_host, $db_pass, $db_user, and $db variables only? Is this possible? Thanks!
  6. Are you saying you are REQUIRED to fix the syntax? I'm not saying their isn't, because I'm not exactly sure, but I don't think you can do a MySQL query that way. I'd recommend you use a way like mine or similar.
  7. I've never seen someone actually putting the code to output in an SQL query. Not sure if it would work, but hey, I don't know if you can do that or not. I've just never seen it before. Anyways: Mind trying this? <?php $query = mysql_query("SELECT `name`,`location`,`number` FROM `people` WHERE 1"); while($grab = mysql_fetch_assoc($query)) { echo $grab['name']. " is from ". strtoupper($grab['location']) .". The ASCII character of the number ". $grab['number'] ." is ". ASCII($grab['number']) ."."; } ?>
  8. GAH! BIEBER? Anyways, thanks for this! I'm still on my quest of learning OOP, and I actually understand most of what you just did. The only thing I'm a bit confused about is the get. Other than that, thanks! I thought a format like this: $variable = People::get($input); Would be for static classes only. And do you mind if I ask, what does the get function do? Highly appreciated, thanks!
  9. You could store their IP in the same table as their username. And then do this: <?php if(mysql_num_rows(mysql_query("SELECT * FROM users WHERE ip = '". $_SERVER['REMOTE_ADDR'] ."' LIMIT 1"))) { echo "You already have an account."; } else { //execute registration code } ?>
  10. Here is a shorter way: <?php $old = "table.birthday"; $new = end(explode('.', $old)); ?>
  11. Bump! Still testing to no luck.
  12. Wut? Then how does a rabbit lose to a wolf? That one comes out correct.
  13. You have an if & else statement with a else statement closing it. Why? Try this: <?php if ($id) { if (!$user->get('id') == 0 || !$userid || $userid != $user->get('id')){ //$url = JURI::root() . 'index.php?' . $component . '&id=' . $id . '&tmpl=component&print=1'; $url=JURI::root().'index.php?'.$component.'&userid='.$_GET['userid'].'&id='.$id.'&tmpl=component&print=1'; for($i=1;$i<count($type);$i++){ $url.='&'.$type[$i].'='.$layout[$i]; } } /*MG made this change here to get the user to got ot set Default Account if they have not one yet. Account Album ID = 27. CaribbeanHeat.tv Main Account.Yah. Mg all the way baby. 042776*/ } elseif(!$file) { $url=JURI::root().'index.php?option=com_muscol&view=album&id=27&tmpl=component&print=1'; for($i=1;$i<count($type);$i++){ $url.='&'.$type[$i].'='.$layout[$i]; }
  14. Yes: $i = -1; foreach($nt as $value) { $i++; echo $nt[$i]."<br/>"; }
  15. you dont need the $i counter, it will automatically set the key value when omitted, unless you want to explicitly set it of course Ooh, thanks, never knew that.
  16. Thanks, I fixed all errors but one. For some reason, a wolf loses to an eagle, and so does a tiger. I mean, it has lower stats, so it should lose compared to tiger and wolf. Newest download: [attachment deleted by admin]
  17. Could this help? <?php mysql_connect(###"); mysql_select_db("###") or die("Unable to select database"); $result = mysql_query("SELECT name FROM business WHERE type ='Restaurant' ORDER BY name"); $numrows = mysql_num_rows($result); $result_row = mysql_fetch_assoc($numrows); if(!$i) $i = 0; foreach($result_row as $value) { $field[$i] = $result_row['name']; } //display for($x = 0; $x < $i; $x++) { echo "Result ". $i ." from the database equals ". $field[$i] . "<br/>"; } ?>
  18. If you have a form, you could always check for a second value using a hidden form. <input type='text' name='id' value='". $ID ."'>
  19. You could use something like this: header("location:url");
  20. I don't see why we can't edit our previous posts, but anyways.....AGAIN...I did a lot of updates to the code, fixed more errors. But for some reason, I get this error: Fatal error: Cannot access protected property rabbit::$damage in C:\wamp\www\OOP\class_li.php on line 20 I thought when a variable was protected, other classes could access it? [attachment deleted by admin]
  21. Did you use the code I gave you? <?php session_start(); $_SESSION['ID'] = $_GET['ID']; //echo id to see if it is what you expect echo $_SESSION['ID']; ?> <iframe src="iframepage.php?ID=<?php echo $_SESSION['ID']; ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="0" border="0" scrolling="Yes" allowtransparency="true" /> </iframe> session_start(); already starts the session. While I'm here, may I ask why you are using session? $_GET['id'] already contains the value you want, why not just make it: <iframe src="iframe.php?ID=<?php echo $_GET['id'] ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="5" border="0" scrolling="Yes" allowtransparency="true" /> </iframe>
  22. Well, I tested it an it worked on my localhost. Are you sure it's not passing it through?
  23. I did a great deal of fixes, new script download found below. [attachment deleted by admin]
  24. Try this code: <?php session_start(); $_SESSION['ID'] = $_GET['ID']; //echo id to see if it is what you expect echo $_SESSION['ID']; ?> <iframe src="iframepage.php?ID=<?php echo $_SESSION['ID']; ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="0" border="0" scrolling="Yes" allowtransparency="true" /> </iframe>
  25. EDIT: Error; Fatal error: Class 'tiger' not found in C:\wamp\www\OOP\class_li.php on line 14 Fixed it, and code updated: <?php require_once('class_li.php'); $character_one = $_POST['character_one']; $character_two = $_POST['character_two']; if(!$character_one || !$character_two) { ?> <form action="index.php" method="POST"> <select name="character_one"> <option value="rabbit" selected="selected">Snake</option> <option value="tiger">Tiger</option> </select> vs <select name="character_two"> <option value="wolf" selected="selected">Wolf</option> <option value="eagle">Eagle</option> </select> <input type="submit" value="BATTLE!"> </form> <?php } else { echo "succes"; $character_battle = new character_battle(); $character_battle->battle($character_one, $character_two); } Yet all I see is success, but nothing else. I'm thinking it may have to do with this block of code in class_li.php class character_battle { public function battle($character_one, $character_two) { $character_one_class = new $character_one(); $character_two_class = new $character_two(); echo $character_one_class->description(); echo $character_two_class->description(); echo $character_one_class->attack($character_one_class->damage); echo $character_two_class->attack($character_two_class->damage); } }
×
×
  • 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.