Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
You enabled error reporting for PHP, but you have nothing to tell you if there is a DB error and what it is. $sql = "INSERT INTO contact_reg (loginip, group_name, place, managerName, managerMobile, managerEmail, category, AstName, AstMobile, AstEmail) VALUES ('1.22.333', 'St. Machael', 'Dubai', 'John', '1233333', 'manager@play1.com', 'kids', 'Ronny', '050123456+', 'tester@test.com')"; $result = mysql_query($sql); if (!$result) { echo 'Error running query: {$sql}<br>Error: ' . mysql_error(); } else { echo 'Record has successfully inserted'; }
-
Are you running these pages on a web server or are you opening them up directly on your PC? PHP files must be requested from a web server that has PHP enabled so it can execute the PHP code and send the output to the browser. You can set up a webserver on your machine if you want using something like XAMPP or WAMP. but, I bet if you look at the source code of the page you will see that ALL of the code from madlib.php is there. You just can't see the PHP code in the display because the HTML considers the PHP opening/closing tags as HTML tags and hides it.
-
You first state that you are using mysqli_, but the connection code you have uses just mysql_. So, something isn't adding up. But, assuming you are using the right connection code for the database queries you are running, then the connection code isn't running on the page that does the insert. Put an echo in the include file that does the connection and go through the process that should insert a record to verify that page is getting called.
-
Need to require either one or another option be completed in form
Psycho replied to jdutton's topic in PHP Coding Help
In case it is not apparent from requinix's post, be sure the $email and $phone validation is within a subset of parens. When there are a bunch of conditions in the same check, I think it's a good idea to "format" the conditions so the structure is visually apparent: elseif ( empty($first_name) || empty($last_name) || empty($species) || empty($date) || empty($time) || empty($reason) || empty($contact) || ( empty($email) && empty($phone) ) ) { header( "Location: $error_page" ); } Also, I probably wouldn't do it in this situation, but if you had several fields and only require that one of them have a value you could do a single empty() check on the concatenated value if(empty($field1.$field2.$field3)) And, last side comment, you are not trim()ing the input values. So, if a user entered a space or spaces into a field it would pass your validation. I would suggest trimming the $_REQUEST value when you set the variables. E.g. $first_name = trim($_REQUEST['first_name']); -
Let user to take picture from webcam/smart phone
Psycho replied to pascal_22's topic in PHP Coding Help
Hmm, can you provide a site where you see this? If it does work it is likely default functionality by the device and not something implemented in the web site. May only apply to Apple or Android or even browser specific. -
Let user to take picture from webcam/smart phone
Psycho replied to pascal_22's topic in PHP Coding Help
On the smart phones where you see the option to take a new picture are you sure you are looking at a web page and not a mobile App? A Java applet would have to be installed, which many users would probably not choose to do. If you can accomplish this with Flash - and nothing additional to install by the user, except the Flash install, then I'd go that route. -
Let user to take picture from webcam/smart phone
Psycho replied to pascal_22's topic in PHP Coding Help
I don't believe there is any way to have the browser interact with the hardware on the user's system/device as it would create a security risk. I believe you would have to create a Java applet that the user would have to install to do this. -
Robot Detection Class - For Your Use
Psycho replied to Muddy_Funster's topic in Beta Test Your Stuff!
Well, I'm not really going to read through all of it - as I'm not planning to use it. But, here is something that stuck out to me public function setExclude($mixed){ if(is_array($mixed)){ foreach($mixed as $key=>$toExclude){ $this->excludes[] = $toExclude; } } else{ $this->excludes[] = $mixed; } } First off, it doesn't take into consideration the possibility of duplicate values. That's easy enough to handle. But, it's also more complicated than it needs to be. No need to do a foreach() loop to add the values when you can simply use array_merge(). Also, you can typecast the input as an array so there would be no need for the if/else condition. function setExclude($exclusions) { //Cast the value as an array $exclusions = (array) $exclusions; //Append to current list of exclusions $this->excludes = array_merge($this->excludes, $exclusions); //Remove duplicates $this->excludes = array_unique($this->excludes); return $this->excludes; }- 14 replies
-
How about using a Wiki? There are plenty of free options available.
-
Robot Detection Class - For Your Use
Psycho replied to Muddy_Funster's topic in Beta Test Your Stuff!
I would never rely upon getting an external file because it just created a single point of failure. And, besides, how often is the file updated? Unless it is continually updated it is a waste to fetch the file and do all the processing. As I stated, I would do ALL the processing (external file and exclusions) and store the results. That way you only need to get the file if a newer one exists and you only need to reprocess if a new file exists or the exclusions have changed. I don't see how that is possible. And, if it is, then you don't need an IF/ELSE since they do the exact same thing. This will return an array of JUST the lines that you need private function getBotData() { $output = array(); $inputArray = file($this->url); foreach($inputArray as $line) { if (strpos($line, 'robot-useragent')!==false) { $output[] = $line; } } return $output; } Use the process Kicken provided to determine if you need to get a new file. Then, change the class to operate as follows: The construct method should just set a URL property of the class an set defaults (e.g. $exclusions). Then have a method to set additional exclusions - but do not process them - just save to an array property. Then have your methods to return the complete list (e.g. __toString). When the user calls that method, check to see if the external file is newer than the cache (or if the cache does not exist). If so, get the new file. Then check if the exclusions are different than the ones in the cache file. If the cached file is good and no changes in exclusions, return the previously saved results. If the cached file is good and there are changes to exclusions, use the cached file to process the new results and save them. If the cached file is not good, download a new one and process it with the current exclusions and save the results. So, you should have an array of ALL the exclusions before ever trying to process the file. Take that array and create an MD5 hash and save that value. You could include it as part of the results file.- 14 replies
-
That was a copy/paste goof, should have been $get_height
-
Try this: public function getFiles() { // create a resrouce pointing to the directory with the files in it on disk $dir = opendir('DIRECTORY'); //path to that directory that is appended to the URL $actualdir = 'PATH FROM WEBSERVER ROOT'; // read the directory looping over the files and populate into // two arrays: one to tracjk the data and one to track the name $typesByDate = array(); $typesByName = array(); while ($fileName = readdir($dir)) { //Skip directories if(!is_file($fileName)) { continue; } //Get type and date from file name $type = substr($fileName, 6, 2); $date = substr($fileName, 6, ; //If no file set for this type or date is newer than last saved, add it if(!isset($typesByDate[$type]) || $typesByDate[$type] < $date) { $typesByDate[$type] = $date; $typesByName[$type] = $fileName; } } //close the directory as we don't need it anymore closedir($dir); //loop through the files building up a list of links $return = ''; foreach($typesByName as $file) { $return .= "<a href='{$actualdir}{$file}'>{$dirArray[$file}</a><br/>"; } return $return; }
-
@AbraCadaver, That won't work as requested. That would find any results where the words exist in any of the fields. The request, as I understood it is where all the words exist in Description, or all the words exist in Title, or all the words exist in Category. @JAMerlino, You should really do this through FULL TEXT searching. This requires modifications to your tables and different ways of running the queries. You can Google how to do that if you want to do it that way. Else, with your current setup, this should work. Seems a little verbose, but it is easily configurable and should be easy to follow. //Create array of all fields to run search against $searchFields = array('Description', 'Title', 'Category'); //Create array of search words $searchWords = array_filter(explode (' ', $search)); //Create template of search parts (with placeholder) $searchParts = array(); foreach($searchWords as $word) { $searchParts[] = "FIELD_NAME LIKE '%{$word}%'"; } //Implode the parts into a complete search string for a field $searchString = "(" . implode(' AND ', $searchParts) . ")"; //Create search strings for all fields replacing placeholder $constructParts = array; foreach($searchFields as $fieldName) { $constructParts[] = str_replace('FIELD_NAME', $fieldName, $searchString); } //Combine into a single string $construct = implode(' OR ' $constructParts);
-
Based upon previous posts I cobbled the below code together. You will need to go through and make sure all field names are correct. Also, I added no logic for conditional display of data (e.g. don't display the "Email" label if a contact does not have a label). I'll leave that to you. In the other threads you were advised to NOT run queries in loops. It is a bad practice and you shouldn't start now. You should run only two queries. One to get the company (and company contact) info. And a second to get the branch (and branch contact info). Then put all of that data into a multi-dimensional array. You should also include only the fields you needs as part of the SELECT statement. Once you have that single array - the output becomes elementary. As I stated above, this was just cobbled together so I'm sure there may be a syntax error or two and I probably messed up many of the field names. But, this should solve your problem if you clean it up. <?php // Retrieve ALL the "company" specific data (including contacts) $query = "SELECT * FROM company LEFT JOIN contact ON company.company_id = contact.company_id WHERE comp_county = 'BERNALILLO' ORDER BY company.comp_name, contact.cont_rank"; $result = mysql_query($query) or die(mysql_error()); // Build the $company_array $company_array = array(); while($row = mysql_fetch_assoc($result)) { if(!isset($company_array[$row['company_id']])) { //Add the company specific data here $company_array[$row['company_id']] = array( 'name' => $row['comp_name'], 'address' => $row['address'], 'phone' => $row['phone'], 'fax' => $row['fax'], 'web' => $row['web'], 'email' => $row['email'] ); } //Add the company contact info here $company_array[[$row['company_id']]['contacts'][] = array( 'name' => $row['contact_name'], 'title' => $row['title'], 'email' => $row['email'] ); } //Run query to get branch info - for ALL companies $query = "SELECT branch.*, contact.* FROM branch JOIN company ON branch.company_id = company.company_id LEFT JOIN contact ON branch.branch_id = contact.branch_id WHERE company.comp_county = 'BERNALILLO' ORDER BY branch.br_name, contact.cont_rank"; $result = mysql_query($query) or die(mysql_error()); //Add branch (and branch contacts) results to $company_array while($row = mysql_fetch_assoc($result)) { $compID = $row['company_id']; $branchID = $row['branch_id']; if(!isset($company_array[]['branches'][$row['branch_id'])) { $company_array[$compID]['branches'][$branchID] = array( 'branch_name' => $row['branch_name'], 'address' => $row['address'], 'phone' => $row['phone'], 'fax' => $row['fax'], 'web' => $row['web'], 'email' => $row['email'] ); } $company_array[$compID]['branches'][$branchID]['contacts'][] = array( 'name' => $row['contact_name'], 'title' => $row['title'], 'email' => $row['email'] ); } // Start building the table for showing results echo "<table border='1' cellpadding='10' cellspacing='0' bgcolor='#f0f0f0' style='margin-left:100px; margin-bottom:20px'>"; // Begin the "foreach" loop for rows in the $company_array foreach($company_array as $company) { echo "<tr><td>\n"; echo "<b>{$company['company_name']}</b><br>\n"; echo "{$company['address']}<br>\n"; echo "{$company['phone']} Fax: {$company['phone']}><br>\n"; echo "Email: {$company['email']}<br>\n"; foreach($company['contacts'] as $contact) { echo "<b>{$contact['contact_name']}</b>, {$contact['title']}<br>\n"; echo "Email: {$contact['email']}<br>\n"; } foreach($company['branches'] as $branch) { echo "<b>Branch {$branch['branch_name']}</b><br>\n"; echo "{$branch['address']}<br>\n"; echo "{$branch['phone']} Fax: {$branch['phone']}><br>\n"; echo "Email: {$branch['email']}<br>\n"; foreach($branch['contacts'] as $contact) { echo "<b>{$contact['contact_name']}</b>, {$contact['title']}<br>\n"; echo "Email: {$contact['email']}<br>\n"; } } echo "</td></tr>\n"; } echo "</table>"; mysql_close(); ?>
-
You've provided incomplete code. There are variable that have not been defined that are being referenced. $targ_w2 = $get_width * 2; $targ_h2 = $get_height * 2; Where are $get_width and $ defined? Also, I see no purpose for creating multiple instances of the same source image.
-
You can also submit your site here (http://www.google.com/addurl.html) and see if Google indexes it any sooner.
-
Robot Detection Class - For Your Use
Psycho replied to Muddy_Funster's topic in Beta Test Your Stuff!
OK, a couple other things. From the manual In the __contruct method a <pre> tag is being echo'd- 14 replies
-
Robot Detection Class - For Your Use
Psycho replied to Muddy_Funster's topic in Beta Test Your Stuff!
Please be aware that I provide criticism in a very direct manner. So, do not read any personal attacks or derogatory intentions in my reply below It is a waste to remotely access and process the file each time this script is run. The script should instead process the file into the final array and cache it locally. Then when the script is run, check to see if the remove file is newer than the last one processed. If not, use the cached file. If so, get the file and process it into a new cache file. I don't understand the "exclude" array. How is someone wanting to use this supposed to know the structure and content of the exclude array? I'm not understanding how the exclusions are done. The sample displayed doesn't make much sense to me. There is an if() statement based upon whether the input is an array or not. But, both the IF and ELSE statement blocks do the exact same thing! The ELSE block would fail for any other input - unless it is an object. I have to assume you didn't test this. For the exclusions you will also need to cache something to prevent reprocessing the data each time. I would suggest having the script accept exclusions (as it does now) and then creating a checksum (e.g. MD5 hash or something similar) of all the exclusions and storing that. Then, when the script runs, verify if the currently generated checksum matches the stored one. If so, no need to process anything. Else, need to process the new exclusions. I see some inefficiencies as well. For example, you explode a line first, then do a check to see if the first element equals "robot-useragent". If it does then there are several lines to act on that record. Why not just do a strpos() check before going to the trouble of exploding the line. Heck, I'd probably create a method to use with array_filter() to remove all lines that do not have "robot-useragent" and then you have an array with just the data that is needed. What is the purpose of the method exclude()? It only takes the input value and passes it to the method runExclusion(). So, why not make runExclusion() a public method and remove the exclusion() method.- 14 replies
-
There really is no way to provide a good answer because without knowing all the details of what EXACTLY you need there's no way to provide any guidance. For example, if all you need to allow is modification of text on existing pages you could probably build something yourself. And, doing that with flat-files is an acceptable solution, in my opinion.. However, if you need to allow changes to styles of that text it gets a little more complicated. And, if you need to allow changes to positioning, images, etc. it gets even more complicated.
-
I'm not sure I really understand the question. But, I think you want to sort such that all records where column 1 = red sort first, then by column 2 = blue, etc. If so, the solution is simple, you can create your sorting conditions as comparisons SELECT * FROM table_name ORDER BY column_1 = 'red', column_2='blue' EDIT: Why is this in the PHP forum? You should know better after 900 posts. Moving to MySQL forum.
-
Why does this always give same result, even when table is empty?
Psycho replied to CGTroll's topic in PHP Coding Help
Yes, it has always been like that. http://www.php.net/manual/en/mysqli.query.php However, there are plenty of other functions that may return a value of 0 that is not false and you must use the type comparison ===. For example, strpos() return the position in which a search string is found. Since 0 is a valid location for the position found and does not mean there was an error. -
Need help displaying variables through functions
Psycho replied to eldan88's topic in PHP Coding Help
No, I mean create a dynamic object. function getAccount($demo = TRUE) { $account = new stdClass(); if($demo) { $account->from_number = "55555555555"; $account->sid = "******************"; $account->token = "*****************"; } else { $account->from_number = "5555555555"; $account->sid = "*****************"; $account->token = "*****************"; } return $account; } $account = getAccount(); var_dump($account); Result stdClass Object ( [from_number] => 55555555555 [sid] => ****************** [token] => ***************** ) -
That makes no sense. Encryption is not a method to be used for making things safe to run in a query. Also, the user has no access to session variables. So, if the value is unsafe - that is because you put it there with an unsafe value.
-
Need help displaying variables through functions
Psycho replied to eldan88's topic in PHP Coding Help
Just return an object. -
CA is the abbreviation for California, and GA for Georgia. "Hom" is a recognized word too. So, is "Gard". So, even your examples are flawed. So you can't even determine what is and is not a word. There is no programming solution for what you ask. You can only compare the words against some other list of "approved" or "recognized" words.