
maxudaskin
Members-
Posts
628 -
Joined
-
Last visited
Everything posted by maxudaskin
-
He obviously did not read the tutorial that I linked. It will take three minutes to read, another minute or two to understand and try out. Yet again, the link is http://www.w3schools.com/sql/sql_select.asp
-
I wish more people would read your signature. It's really something that not many people learn, because it's not really a PHP coding practice, but an SQL coding practice. the * is not needed? SQL Statement Tutorial
-
I wish more people would read your signature. It's really something that not many people learn, because it's not really a PHP coding practice, but an SQL coding practice.
-
Here's a step by step explanation. You cannot call a POST or GET value by just typing in a variable. Let's say that your POST field is $feedbackemail. Nowhere in your code is $feedbackemail specified. If your input field is named feedbackemail, you must use the syntax $_POST['feedbackemail']. Add this to the top of the page, just after your opening tag (<?php): ini_set("error_reporting", "true"); error_reporting(E_ALL|E_STRCT);
-
if is not a function. It's merely an operator (correct me if I'm using the wrong terms). isset is a function. It checks if the variable that you are looking for actually exists in memory and returns true if it is, false if it isn't. empty is a function. It checks if the variable is in memory and if it's not NULL, '' or whatever it will juggle as an empty variable. It returns false if one of those conditions are false. I suggest that you do some reading of these PHP tutorials on W3Schools.
-
Reading data from .xml file into .txt file with php script
maxudaskin replied to foggykt's topic in PHP Coding Help
An XML file is essentially a TXT file. If you want to copy it all over without changing it, you can just change the file type. -
Is it possible to display an obscured value from a mysql database?
maxudaskin replied to jdock1's topic in PHP Coding Help
I believe that your issue can be solved by using trim() before sending it through the obscuring function. Here's an updated class <?php class StringObscure { /** * Obscure String * Takes a string and changes some characters to obscure it * @param string $string // The string to obscure * @param int $num_to_obscure The number of characters in the string to obscure * @param string $obscure_char The string to obscure with (can be more than one character long) */ function obscure($string, $num_to_obscure = -1, $obscure_char = '*') { if(empty($obscure_char)) // Prevent $obscure_char from being empty $obscure_char = '*'; if($num_to_obscure == -1) { // If there is no input for the amount of characters to obscure $num_to_obscure = round(strlen($string) / 2); // Obscure half of the characters } if($num_to_obscure > strlen($string)) { // Make sure that the number to obscure is no greater than the length of the string $num_to_obscure = strlen($string); } $string = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); // Split string into array $obscured = array(); for($i = 0; $i < $num_to_obscure; $i++) { // Obscure characters do { $rand = rand(0, count($string)); } while (array_key_exists($rand, $obscured)); $string[$rand] = $obscure_char; // Obscure specific character $obscured[$rand] = true; // Create key } return implode('', $string); } /** * Obscure String w/Percentage * Takes a string and changes some characters to obscure it using a percentage of the string length * @param string $string // The string to obscure * @param int $pct_to_obscure The percentage of characters in the string to obscure * @param string $obscure_char The string to obscure with (can be more than one character long) */ function obscurePercentage($string, $pct_to_obscure = -1, $obscure_char = '*') { if(empty($obscure_char)) // Prevent $obscure_char from being empty $obscure_char = '*'; if($pct_to_obscure == -1) { // If there is no input for the amount of characters to obscure $num_to_obscure = round(strlen($string) / 2); // Obscure half of the characters } else { if($pct_to_obscure > 100) { // Make sure that the percentage is 100% or less $pct_to_obscure = 100; } else { if($pct_to_obscure < 0) { // Make sure that the percentage is 0% or greater $pct_to_obscure = 0; } } $pct_to_obscure = $pct_to_obscure / 100; // Turn the percentage into a decimal $num_to_obscure = round(strlen($string) * $pct_to_obscure); // Calculate the number of characters to be obscured } $string = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); // Split string into array $obscured = array(); for($i = 0; $i < $num_to_obscure; $i++) { // Obscure characters do { $rand = rand(0, count($string)); } while (array_key_exists($rand, $obscured)); $string[$rand] = $obscure_char; // Obscure specific character $obscured[$rand] = true; // Create key } return implode('', $string); } } -
Is it possible to display an obscured value from a mysql database?
maxudaskin replied to jdock1's topic in PHP Coding Help
I taught myself PHP using online tutorials such as W3Schools.com. I took programming classes in highschool for Turing and Java, which only helped me understand the concept of classes. I'm still learning, as any good programmer, about new stuff every time I write some code. Regarding writing code fluently, it takes practice, but some people still cannot grasp the concept. It requires very logical thinking for the most part, and it shows in other parts of my life (I don't get emotional, I try to think of a logical response to everyday situations). I'm going to take a look at the issue you're describing now. -
Is it possible to display an obscured value from a mysql database?
maxudaskin replied to jdock1's topic in PHP Coding Help
I've turned it into a class with two distinct functions. It doesn't really need to be in a class, but I wanted to upload it to phpclasses.org. <?php class StringObscure { /** * Obscure String * Takes a string and changes some characters to obscure it * @param string $string // The string to obscure * @param int $num_to_obscure The number of characters in the string to obscure * @param string $obscure_char The string to obscure with (can be more than one character long) */ function obscure($string, $num_to_obscure = -1, $obscure_char = '*') { if($num_to_obscure == -1) { // If there is no input for the amount of characters to obscure $num_to_obscure = round(strlen($string) / 2); // Obscure half of the characters } if($num_to_obscure > strlen($string)) { // Make sure that the number to obscure is no greater than the length of the string $num_to_obscure = strlen($string); } $string = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); // Split string into array $obscured = array(); for($i = 0; $i < $num_to_obscure; $i++) { // Obscure characters do { $rand = rand(0, count($string)); } while (array_key_exists($rand, $obscured)); $string[$rand] = $obscure_char; // Obscure specific character $obscured[$rand] = true; // Create key } return implode('', $string); } /** * Obscure String w/Percentage * Takes a string and changes some characters to obscure it using a percentage of the string length * @param string $string // The string to obscure * @param int $pct_to_obscure The percentage of characters in the string to obscure * @param string $obscure_char The string to obscure with (can be more than one character long) */ function obscurePercentage($string, $pct_to_obscure = -1, $obscure_char = '*') { if($pct_to_obscure == -1) { // If there is no input for the amount of characters to obscure $num_to_obscure = round(strlen($string) / 2); // Obscure half of the characters } else { if($pct_to_obscure > 100) { // Make sure that the percentage is 100% or less $pct_to_obscure = 100; } else { if($pct_to_obscure < 0) { // Make sure that the percentage is 0% or greater $pct_to_obscure = 0; } } $pct_to_obscure = $pct_to_obscure / 100; // Turn the percentage into a decimal $num_to_obscure = round(strlen($string) * $pct_to_obscure); // Calculate the number of characters to be obscured } $string = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); // Split string into array $obscured = array(); for($i = 0; $i < $num_to_obscure; $i++) { // Obscure characters do { $rand = rand(0, count($string)); } while (array_key_exists($rand, $obscured)); $string[$rand] = $obscure_char; // Obscure specific character $obscured[$rand] = true; // Create key } return implode('', $string); } } // Examples $str = 'Random String to be obscured...'; echo 'String before obscuring: ' . $str; // Outputs string, unaltered echo 'String after obscuring: ' . stringObscure::obscure($str); // Outputs string with half of the characters obscured echo 'String after obscuring: ' . stringObscure::obscure($str, 10); // Outputs string with ten of the characters obscured echo 'String after obscuring: ' . stringObscure::obscure($str, 7, '-'); // Outputs string with seven of the characters changed to - echo 'String after obscuring: ' . stringObscure::obscurePercentage($str, 25); // Outputs string with 25 percent of the characters obscured -
Is it possible to display an obscured value from a mysql database?
maxudaskin replied to jdock1's topic in PHP Coding Help
Got it! <?php function obscure($string, $num_to_obscure = -1, $obscure_char = '*') { if($num_to_obscure == -1) { // If there is no input for the amount of characters to obscure $num_to_obscure = round(strlen($string) / 2); // Obscure half of the characters } $string = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); $obscured = array(); for($i = 0; $i < $num_to_obscure; $i++) { // Obscure characters do { $rand = rand(0, count($string)); } while (array_key_exists($rand, $obscured)); $string[$rand] = $obscure_char; // Obscure specific character $obscured[$rand] = true; // Create key } return implode('', $string); } And my test that proves it works: <?php $str = 'Random String to be obscured...'; echo 'String before obscuring: ' . $str; echo '<br />'; echo 'String after obscuring: ' . obscure($str); Here are three different outputs (reloads). String before obscuring: Random String to be obscured... String after obscuring: **n*om S*ri** *o****ob**u**d...* String before obscuring: Random String to be obscured... String after obscuring: Ran**m **r**g**o**e o**c*re**..* String before obscuring: Random String to be obscured... String after obscuring: ****om S***ng *o*b* obscu***.*.** This is one function that I'm going to keep somewhere, because it may come in handy sometime... -
Is it possible to display an obscured value from a mysql database?
maxudaskin replied to jdock1's topic in PHP Coding Help
Im about to post it on freelancer.com. Thats all I can think to do! I could possibly do this thhrough mysqls substring, but I read the manual and its just too confusing and doesnt explain it all too well Give me another try before you go spending money... -
Creating a Multi-Dimensional Array from DB
maxudaskin replied to maxudaskin's topic in PHP Coding Help
I think that is exactly what I was looking for... thanks -
How to create a text file while runnning PHP program from browser?
maxudaskin replied to reksss's topic in PHP Coding Help
Please remember to put your code inside of tags. It makes it much easier for everyone else to read it, as it highlights the code. -
Creating a Multi-Dimensional Array from DB
maxudaskin replied to maxudaskin's topic in PHP Coding Help
I don't think you quite understand what I'm trying to do. The array can have as many levels as the user wants it to. The database has all of the items as a separate row. If an item is a child of another item, it must be places as a sub array to that item. If there is a child to that sub-array, it must be placed as a sub-array to the sub-array (and so on). -
Creating a Multi-Dimensional Array from DB
maxudaskin replied to maxudaskin's topic in PHP Coding Help
Doesn't quite help. I understand the concept of multi-dimensional arrays. I'm trying to get the information from my database (effectively a two dimension array (Dim1: Row, Dim2: columns) into a variable dimension array (Items and children [and children's children, ect]). -
Creating a Multi-Dimensional Array from DB
maxudaskin replied to maxudaskin's topic in PHP Coding Help
I hate to bump this topic, but I am starting to get desperate. Anyone got any ideas? -
He chose to use a strict comparison, so I left it there. Really, unless it outputs some of the values as a string (1 vs '1'), then it should be fine.
-
+1
-
Using your words directly, it should do what you want, although, you don't need those extra set of parenthesis around each clause. <?php if (($news['accounttyperaw'] !== 0) || ($news['accounttyperaw'] !== 1)) // Can be: if ($news['accounttyperaw'] !== 0 || $news['accounttyperaw'] !== 1) If you want to do two different things for each clause, I would do: <?php if ($news['accounttyperaw'] !== 0) { // do something } else { if($news['accounttyperaw'] !== 1) { // do something else } }
-
<?php if ($row_cnt > 0){ // This is pretty much saying, "if there are more than zero rows, return an error" // I assume you want it to return an error if there is less than one row? if ($row_cnt < 1){
-
"time"-related issue. Error in the code?
maxudaskin replied to xwishmasterx's topic in PHP Coding Help
Are you getting any erroneous result from PHP or MySQL? If so, please provide the errors. -
Was it the SQL string?
-
Spend a few minutes reading (or more if you like). GET POST
-
Try this. <?php $sql = "SELECT * FROM `purchases` WHERE `uid` = '$user_id' AND nid = '$id'"; // If you're using double quotes, you can leave the variables in there $query = mysql_query($sql) or die (mysql_error()); $row_cnt = mysql_num_rows($query); echo "The SQL query $sql returns $row_cnt rows."; Put that in. I have a feeling that it is because you didn't put your single or double quotes around the values of uid and nid.