Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. nope, just add a variable in your config which you set to true for development but set to false for live
  2. <?PHP $result=mysqli_query($db,$query); if (is_resource($result)) { // Check result first echo "<table border="0">"; // We start the table while($debt_history=mysqli_fetch_array($result)){ echo "tr><td>{$debt_history['cnotes']}</td></tr>"; echo "<tr><td>{$debt_history['cusercode']}</td></tr>"; echo "<tr><td>{$debt_history['cactiontype']}</td></tr>"; echo "<tr><td>{$debt_history['debalance']}</td></tr>"; echo "<tr><td>{$debt_history['ihistoryid']}</td></tr>"; } echo "</table>"; // We close the table } ?> p.s.: use code tags, you can add them by pressing on the # then paste your code and hit it again to close the code tags!
  3. Yes, that is a crucial aspect of a database abstraction library, but if you'll notice, cmgmyr was not out to create a database abstraction library. He says "MySQL class", which leads me to believe that he's not going to be using it with a postgres/sqlite/etc. database. yes, ofcourse but when they want to play with fire, you might aswell give them a lighter..
  4. when you are creating a database abstraction class, make sure it will supports more then just one type of database (eg: mysql, mysqli, postgresql, ...) class DB { var $container; var $conn; function DB($container = 'MySQL', $options = '') { $this->container = new $container($options); } function connect($server, $username, $password) { $this->container->connect($server, $username, $password); } } // container MySQL class MySQL extends DB { function connect($server, $username, $password) { $this->conn = mysql_connect($server, $username, $password); } } // container PostGreSQL class PostGreSQL extends DB { function connect($server, $username, $password) { $this->conn = pg_connect(sprintf("host=%s user=%s password=%s", $server, $username, $password)); } }
  5. I am not sure, that i am posting this in the correct section. But because the whole idea will be mostly "object-oriented".. So: The Problem: Before i start of programming my application, i make sure i have got a complete UML-diagram of all my classes, and a database model diagram, however this is still not enough, because i mostly end up with NULL... What i am asking: Which steps should i take before i start off programming? What diagrams should i be using? How can i make sure my code will be reusable and extendable? How do i make it extendable? What are layers, and how do i use them (domain layer, security layers, abstraction layers, ..)? ... If you could just give me a step-by-step guide that would be terrific, the only problem is, that their is no such guide on the net! I am not asking you how i need to program, but everything you do before you start programming! what diagrams do you draw?, or what do you write down on your notepad? ... any help is greatly appreciated (also if you know alot of technical words and know what they mean (eg: critters, etc..), may be posted aswell) thank you in advance
  6. are you using flowcharts and UML-diagrams? Because besides that, i think its quite neat!
  7. did you already tried this?: "SELECT * FROM docs WHERE description = '{$keyword}'";
  8. if you are removing duplicates, their won't be much to put in your top 10 A DAM ARK ZERO NOR OR A DAM ARK RE NOR ORZO A DAM ARK ERR ON ORZO A DAM ARK ERR NO ORZO A DAM ARK ERR NOR ZOO A DAM RAZOR KRONE OR A DAM RAZOR ERR NOOK A DAMN OKRA ERR ORZO A DAMN ARK ERROR ZOO A DAMN ARK RE ORZO OR would become ZERO ON NO KRONE NOOK OKRA ERROR then for your longest words KRONE // longest 5 (assuming KRONE and ERROR is found only once) ERROR // same the php code used: $wordList=explode("\n",str_replace("\n"," ",$txtwordlist)); $long=array("len" => 0,"word" => ""); foreach ($wordList as $word) { $curr=strlen($word); // this will give you only the longest word the complete string, // use $long['len'][] to get all longest words if ($curr>$long) { $long['len']=$curr; $ong['word']=$word; } }
  9. if you get the 'headers already sent' problem you should try the following: <?php ob_start(); ob_end_clean(); header("Location: thankyou.php"); ?> otherwise i would suggest you use, javascript: <?php // instead of header() use: echo "<script> window.location.href = 'thankyou.php'; </script>"; ?>
  10. yeah, atleast when your form has method="post", otherwise you used change the 'POST' part to 'GET' the only problem is that your browser has his REQUEST_METHOD set to 'GET' by default! I only used this because i did not found any _POST parts in your posted php code, i however use a different method (when writing top-down, and not object oriented): <?php $error = ""; // contains all reported error's $showForm = true; // is the form still required to be displayed? if ((strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0) && (count($_POST) != 0)) { // This makes sure the global _POST atleast contains more then 0 elements // error checking, a favourite of mine: if (strip_tags($_POST['post_element']) != $_POST['post_element']) $error .= "• You are not allowed to use html in your 'post_element'<br />"; // blabla... if (strlen($error) == 0) { // no error's where reported, so the form is no longer required // i use this method, so error's are always displayed above the form, not in or below it! $showForm = false; } } if ($showForm) { // blabla my html form! } ?> when i press modify above my post, it says that my session expired, and when i do a direct modify, it inserts &#160; why is this not being converted?
  11. sure their is, no problem xD because you did not provide any code, i will be using assumptions <?php // assuming we are connected to a database with type MySQL // and we have already queried the database, and saved that in a variable called $result... while ($row = mysql_fetch_assoc($result)) { echo substr($row['article_body'], 0, 186) . "..."; // displays 186 characters from your article printf("<p><a href='article.php?id=%s'>Read More</a></p>", $row['article_id']); // the read more link } // adjust to your own needs, it is not the best example but it should get you started // from programmer to programmer, i would also give you the advice to "abuse" the search function option // on www.php.net, so you can look up functions and what they do, like substr() for exampe! ?>
  12. a possible solution could be using AND instead of OR, another solution is using LIKE '%$var%', if you only want one record just add LIMIT 1 (added in example) to the end of the query (i added { and } which executes variables inside a string, but it is also nice so you can see the difference between the variable and the rest of the query! <?php $result = mysql_query("SELECT * FROM members WHERE companyname LIKE '%{$companyName}%' OR postcode LIKE '%{$postCode}%' OR membernumber LIKE '%{$memNo}%' LIMIT 1") or die(mysql_error()); ?> yeah, my 100th post xD
  13. so you always get two records in this order?: 1. C:/Program Files/xampp/htdocs/epeople/uploads/2001_0116_222704AA.JPG 2. C:/Program Files/xampp/htdocs/epeople/uploads/ comes from: $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; well in the first case a file has been submitted, in the second it isn't, so your database is called 2 times, the first time from the form the second time because the page is loaded! ok then try this: mysql_select_db($database_elvisdb, $elvisdb); if ((strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0) && (count($_POST) != 0)) { // when your page loads the first time, should this return 0 $insertSQL = sprintf("INSERT INTO images (imageName, usnm) VALUES ('%s', '%s')", addslashes($uploadFilename), addslashes($user)); $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error()); }
  14. well actually that is a very good question xD, it probably has something to do with those 0's and 1's called bits xD, and ofcourse the class scope which only allows to declare properties (which represent your variables) or methods (which represent functions) for more information on programming in OOP: http://www.phpfreaks.com/tutorials/150/0.php
  15. The Problem, everytime the script was executed, would only the path be available to insert into the database, until the user submitted the form, and then not only the path but also a filename would be available, creating those strange rows in your database. <?php require_once('Connections/elvisdb.php'); ?> <?php // session needs to be started before, any output can be send.. session_start(); // filename: upload.processor.php // first let's set some variables // make a note of the current working directory, relative to root. $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']); // make a note of the directory that will recieve the uploaded file $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; // make a note of the location of the upload form in case we need it $uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'uploadform.php'; // make a note of the location of the success page $uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'uploadsucs.php'; // fieldname used within the file <input> of the HTML form $fieldname = 'file'; // Now let's deal with the upload if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0) { // validation... since this is an image upload script we should run a check // to make sure the uploaded file is in fact an image. Here is a simple check: // getimagesize() returns false if the file tested is not an image. if (false === @getimagesize($_FILES[$fieldname]['tmp_name'])) exit('not an image.'); // make a unique filename for the uploaded file and check it is not already // taken... if it is already taken keep trying until we find a vacant one // sample filename: 1140732936-filename.jpg $uploadFilename = $uploadsDirectory.$_FILES[$fieldname]['name']; // now let's move the file to its final location and allocate the new filename to it if (is_uploaded_file($_FILES[$fieldname]['tmp_name'])) @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename); // retrieve username $user = $_SESSION['MM_Username']; // select the appropriate database mysql_select_db($database_elvisdb, $elvisdb); // create query, corrected to be in compliance with the sprintf() manual $insertSQL = sprintf("INSERT INTO images (imageName, usnm) VALUES ('%s', '%s')", $uploadFilename, $user); // mysql_select_db($database_elvisdb, $elvisdb); // one select should be more then enough! // use mysql_ping() to see if a connection is still open $Result1 = @mysql_query($insertSQL, $elvisdb) or die(mysql_error()); } echo $uploadfilename; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form name="form1" id="Upload" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" method="POST"> <h1> Upload form </h1> <p> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"> </p> <p> <label for="file">File to upload:</label> <input id="file" type="file" name="file"> </p> <p> <label> <input type="text" name="textfield" /> </label> </p> <p> <label for="submit">Press to...</label> <input id="submit" type="submit" name="submit" value="Upload me!"> </p> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html>
  16. /** * This script will receive the values defined in the form fields "name" & "password", * i am assuming your REQUEST_METHOD is set to POST, if not change method="post" * strcasecmp() compares strings case insensitive */ if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0) { if (isset($_POST) && (count($_POST) != 0)) { // 0 elements would be useless execution of code if (strcasecmp(strip_tags($_POST['name']), $_POST['name']) != 0) exit('not allowed to use html in your username!'; if (strcasecmp(strip_tags($_POST['password']), $_POST['password']) != 0) exit('not allowed to use html in your password!'; // will not be executed if one of the above two validates as true $username = $_POST['name']; $password = $_POST['password']; $db = @mysql_connect('localhost', 'my_name', 'my_password'); if (!is_resource($db)) exit('could not connect to database server.'); if (!@mysql_select_db('shyness_phpb1')) exit('could not select the database.'); // + added LIMIT 1, making sure we only will validate one row from the database $q = sprintf("SELECT * FROM phpbb_users WHERE user_name = '%s' LIMIT 1", $username); $res = @mysql_query($q, $db); if (!is_resource($res)) exit(mysql_errno() . " : " . mysql_error()); // experiment with the provided built-in mysql functions /** * using mysql_fetch_assoc() instead of the mysql_fetch_array() * mysql_fetch_assoc() only returns an associative array instead of an numeric * mysql_fetch_array() returns both, can be manipulated when you pass MYSQL_ASSOC as second argument * * What we are doing here, is not the best practice when it comes to validating users, * another method should be required! */ while ($r = @mysql_fetch_assoc($res)) { if (strcasecmp($r['user_password'], $password) == 0) { // this time i used strcasecmp() which is case insensitive, might solve your problem! printf("the password match the name provided, helloooo<br />\n"); } else { printf("no match!<br />\n"); } } } }
  17. sure, no problem, we are here to help <? /** * $username, so i assume you also have a variable called $password? */ if (isset($username) && !empty($username)) { // just a few extra checks added, so that we know the variable exists and is not empty /** * mysql_connect returns a database resource, which we will store and use later on * to execute queries etc... */ $db = @mysql_connect($dbhost,$dbuser,$dbpasswd); mysql_select_db($dbname); /** * assuming your table is using the fields (user_name, user_password) * + added WHERE clause so you do not get all records, just those who you are going to need! */ $q = sprintf("SELECT * FROM phpbb_users WHERE user_name = '%s'", $username); /** * $db is a resource to your database * its optional as second argument for mysql_query, * but it would be good practice to write it anyway */ $res = @mysql_query($q, $db); while($r = @mysql_fetch_array($res)) { //echo $r['user_name'] . "<br>"; // check http://be.php.net/manual/nl/function.strcmp.php for more information on strcmp function if (strcmp($r['user_password'], $password) == 0) { print "The name and password matched, heloo<BR>\n"; } } } else { // No username print "The Name & password does not match<BR>\n"; } ?>
  18. ignace

    & question

    http://www.phpfreaks.com/forums/index.php/topic,113143.msg459583.html#msg459583
  19. oh ok, i will look into the problem and post the correct code
  20. well finally someone with zero replies and a question i can answer :D using bitwise operator with variables: [code] <?php # the bitwise operator $value1 = "ignace"; $value2 &= $value1; echo $value2; ?> [/code] so $value2 now holds the value of $value1, however $value2 does not hold a copy no it holds a reference to the variable $value1, meaning that whenever i change the value of $value2 the value of $value1 will be changed too. If you have any experience with c++ you will know that $value2 then holds the address of $value1 on the memory (not really important now, but nice to know) using bitwise operator with functions: [code] <?php $value1 = "ignace"; function insertIt(&$value) {    $value = "not ignace"; } insertIt($value1); echo $value1; # output: not ignace ?> [/code]
  21. [code] <input type="hidden" name="IP_Address" value="<?php echo $_SERVER['REMOTE_ADDR'];?>" /> [/code] this is a hidden field, and is not being displayed to the user (unless they do view - source) so when he submit the form you will be able to "capture" his ip by using: [code] <?php # get the actual ip address by using the associative key created by the form (IP_Address) $ip = $_REQUEST['IP_Address']; # display ip echo $ip; ?> [/code]
  22. well i use this code for all kinda things but in general for alternate row coloring, because the most row coloring solutions are mostly also temporarily (so until you remove a record) because they forgot that you can delete records... messing up my website, and it colors... this however i found a more definitive solution. don't mistake me for a proffesional, because just like the most users of this forum i am a noob seaking answers to my questions, and sharing the information i already received.
  23. the problem may lie in the use of mysql_real_escape_string(); I however never use this function cause whenever i use this, the whole script does not work, mostly because the before mentioned function "real" escaped everything leaving nothing to return :D
  24. the code as requested: images.php [code] <?php # images.php if (!function_exists("getMediaType")) { include "../components/functions.php"; } # declare/initialise variables $Img    = $_REQUEST['f']; $Folder = "../media/images/"; $Ext    = explode(".", $Img); $MT     = getMediaType(array_pop($Ext)); if ($MT <> "") { # change to the correct folder chdir("{$Folder}"); # submit header information //header("content-type: image/{$MT}"); //header("content-disposition: attachment; filename={$Name}"); # read the file to assure the file and his content is being submitted. readfile("{$Name}"); } ?> [/code] index.php [code] <?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- W3C XHTML 1.0 Strict Standard Template --> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl"> <head> <title>laboratory :: sticking needles up php's ass</title> <meta http-equiv="robots" content="noindex,nofollow" /> <meta http-equiv="pragma" content="nocache" /> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" /> <meta http-equiv="content-style-type" content="text/css" /> </head> <body> <img src="modules/images.php?f=an_image.gif" width="105" height="105" /><br /> </body> </html> [/code]
  25. whenever you delete a record from your database, you will get two even's or odd's after eachother (example you delete record 3 meaning that record 2 and 4 will return 0 which makes them both even (what is actually correct, but will mess up our row coloring/..)). now my code however (the sloppy, messy one :D) [code] <?php if (isset($tmp)) {    unset($tmp);    $type='odd'; } else {    $tmp = 1;    $type='even'; } ?> [/code] @Crayon Violent: i did not steal it from any other script, i created it myself, not that i am proud of it or anything because it is very unproffesionally written, but it always get the job done! so when you use this piece of code in your loop, the first time $tmp won't exist making the first row even the next time $tmp does exist and is being unset(); so the current row is odd, the next time $tmp does not exist making it again even, etc, etc..
×
×
  • 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.