-
Posts
5,449 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
additionally, you need to have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini on your development system so that php will help you by reporting and displaying all the errors it detects. you would have been getting a number of error messages due to the mixing of mysql (no i) and mysqli functions that don't work together.
-
please see this forum section's sticky thread - http://forums.phpfreaks.com/topic/150979-this-board-is-not-a-code-repository/ we are not really here to help you find things you are looking for, but to help with actual code/programming problems.
-
Changed php version now php scripts not working?
mac_gyver replied to rocky48's topic in PHP Coding Help
i recommend that you read the relevant php version migration sections in the php documentation so that you are aware of what has changed in php over time that will affect your code - http://us3.php.net/manual/en/appendices.php in just scanning the list of backward incompatible changes for the version numbers you mentioned, the two most likely causes of your scripts no longer working is the removal of register_globals and/or magic_quotes_xxxxxx. -
In need of a miracle. Some emails still not being received.
mac_gyver replied to njdubois's topic in PHP Coding Help
dnsstuff has a number of test services. here's the main (free) one for your domain - http://www.dnsstuff.com/tools#dnsReport|type=domain&&value=marcomtechnologies.com there are some warn and fail results that may be relevant to your email problems. they also have paid services (which i have not use and cannot vouch for) that may be of help. -
where in your code are you setting $row at? when debugging code, you want to display all the errors to get php to help you.
-
so, if there is a second person, there would be a nonempty $fullname2 (your posted code is testing if it is not equal to a space ' ', which is likely the cause of your extra inserted record.) the only logic would be to test if $fullname2 is present and use $callsign for the `with` field. $callsign2 would use used as is, it's either a callsign or an empty string. if($fullname2 != ''){ // note, this is an empty string '', not a space ' ' // second person fields have information in them $sql="INSERT INTO `mytable` (`callsign`, `fullname`, `with`) VALUES ('$callsign2', '$fullname2', '$callsign')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } }
-
Please use the forum's bbcode tags (the edit form's <> button) around code when posting it in the forum. i edited your post above. this makes it easier to read code. it would help if you reposted your sample data, but use var_export() on it so that someone could copy it as runnable php code.
-
this is code (untested since i don't have any swish code) based on your previous thread, using the swish data seek method, hopefully you can learn from this - <?php // business logic - determine what to do on the page and get/produce the data that's needed for the content on the page $limit = 10; // pagination number of rows per page // get any search term (required) $search_term = isset($_GET['q']) ? trim($_GET['q']) : ''; if($search_term != ''){ try { $swish = new Swish('/var/www/html/pdf2/index.swish-e'); // get and run query from url query string $result = $swish->query($search_term); // at this point, you know how many matches there are and can calculate the number of pages // Find out how many items are in the table $totalItems = $result->hits; // find how many pages are needed $totalPages = ceil($totalItems / $limit); // Find out which page we are on $page = min($totalPages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array( 'options' => array( 'default' => 1, 'min_range' => 1, ), ))); // Calculate the offset for the query/result set $offset = ($page - 1) * $limit; $data = array(); if($totalItems > 0){ // at least one result // the calculated $offset is used in the following to seek to the correct starting row $result->seekResult($offset); $x = 1; // loop until no more rows or $limit has been reached while(($r = $result->nextResult()) && $x <= $limit) { $data[] = $r; $x++; } // get company/country information (only if there are results to display) $file = '/var/www/html/active_colist.csv'; $fh = fopen($file, 'r'); $companies = array(); $row = fgetcsv($fh, 1024); // ignore header while ($row = fgetcsv($fh, 1024)) { $companies[$row[0]] = array('company' => $row[1], 'country' => $row[3]); //changed line } fclose($fh); } } catch (SwishException $e) { trigger_error($e->getMessage()); die('Sorry, the application experienced an error and cannot run.'); } } // presentation logic - take the data produced by the business logic above and output the html document // build pagination here... $pagination_links = ''; if(isset($totalPages) && $totalPages > 1){ // more than one page // Some information to display to the user $start = $offset + 1; $end = min(($offset + $limit), $totalItems); // "back" link if($page > 1){ $_GET['page'] = 1; $qs = http_build_query($_GET, '', '&'); $prevlink = "<a href='?$qs' title='First page'>«</a>"; $_GET['page'] = $page - 1; $qs = http_build_query($_GET, '', '&'); $prevlink .= " <a href='?$qs' title='Previous page'>‹</a>"; } else { $prevlink = '<span class="disabled">«</span> <span class="disabled">‹</span>'; } // "forward" link if($page < $totalPages){ $_GET['page'] = $page + 1; $qs = http_build_query($_GET, '', '&'); $nextlink = "<a href='?$qs' title='Next page'>›</a>"; $_GET['page'] = $totalPages; $qs = http_build_query($_GET, '', '&'); $nextlink .= " <a href='?$qs' title='Last page'>»</a>"; } else { $nextlink = '<span class="disabled">›</span> <span class="disabled">»</span>'; } $pagination_links = "<div id='paging'><p>$prevlink Page $page of $totalPages pages, displaying $start-$end of $totalItems results $nextlink</p></div>"; } ?> <html> <head></head> <body> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search</h2> <form method="get" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <input type="text" name="q" size="30" value="<?php echo htmlentities($search_term); ?>" /> <input type='submit' value='Submit'> </form> <?php if($search_term != ''){ ?> <h2>Search Results</h2> Found <?php echo $totalItems; ?> match(es) for '<?php echo htmlentities($search_term); ?>'. <?php echo "<div>$pagination_links</div>"; // display pagination at the top of data // iterate over result set foreach($data as $r) { ?> <p> <?php echo $r->swishreccount; ?> <strong> <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (score: <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?><br /> <?php //Split a filename by . $filenames = explode(".", $r->swishdocpath); //get 3 chars from $filenames to $country $wvb_number = substr($filenames[1],1,12); $country = substr($filenames[1],1,3); echo 'Country: '.$companies[$wvb_number]['country']."<br />"; //echo 'Country Name: '.$country."<br />"; //$filenames[2] = explode(".", $r->swishdocpath); $year = substr($filenames[2],0,4); echo 'Year: '.$year."<br />"; //$filenames = explode(".", $r->swishdocpath); //$wvb_number = substr($filenames[1],1,12); echo 'WVB Number: '.$wvb_number."<br />"; echo 'Company Name: '.$companies[$wvb_number]['company']; //echo 'Country: '.$companies[$wvb_number]['country']; echo '</p>'; } // end of data display loop echo "<div>$pagination_links</div>"; // display pagination at the bottom of data } // end search results ?> </body> </html> btw - again not trying to pick on you, but are you testing your current code? what happens after you preform one search (or your search doesn't match anything)? you are not redisplaying the search form, so the visitor doesn't have any direct way of searching again. in the above code, the display of the search form is unconditional.
-
what you are asking can be accomplished, but as stated in one of your previous threads, requires that the code on your page be organized correctly (which Psycho has now also told you is needed.) also as stated in the previous thread, to paginate using an array requires that you store the result from your Swish query in that array, in a session variable (there's little point in using the array method over using the swish data seek method if you are not saving any processing time by doing it since it requires more program logic to be written for the array method.) not trying to pick on you, but do you know where in your current code you are getting the result from the Swish query so that you could modify it to use either the Swish data seek or the array method for pagination? btw - the part of the pagination code you found that is getting and modifying the url's query string parameters can all pretty much be replaced with a http_build_query() statement.
-
How to store session in database help please
mac_gyver replied to lovephp's topic in PHP Coding Help
storing session data in a database is actually less secure than using the default file session save handler, because with the database, the security is now dependent on how strong your database credentials are, how well access to the database server has been limited, and on how secure ALL of your code that has access to that same database is. what sort of problem are you having that you are trying to solve? -
Help with basic PHP website that works with MySQL database
mac_gyver replied to tekkenfan2's topic in PHP Coding Help
the point of programming help forums are for you to make an attempt at doing the work and then you ask a specific question or post a specific error or symptom and the relevant code you need help with only after you get stuck and cannot solve the problem yourself. do you have some code you need help with or a specific question that you could not find the answer for? -
some sql queries that demonstrate the method described above. get the range id (to identify each range when build the checkboxes and using the submitted checkbox data), low/high values (to produce the range label), and the count of products for each ranges (including ranges with no matching products, to get only ranges with products, change the left join to just a join) - Select r.id, r.low, r.high, count(p.price) as num from ranges r left join products p on p.price between r.low and r.high group by r.id order by r.low get the products that match a selected range(s) (range id's 1 or 2 in this example) - Select p.* from products p join ranges r on p.price between r.low and r.high and r.id in(1,2) sample of what the ranges table would look like - "id","low","high" 1, 0.00, 25.99 2, 26.00, 50.99 3, 51.00, 99.99
-
there are some problems with the posted query/code. because you are using an aggregate function in the sql query - count(), but are not using group by in the query, you are only getting one row in the result set. this will give you a count for the products having that particular price range, but doesn't scale to handling other ranges of prices using one query. also, by storing the prices with the $ character and as strings, you will not be able to handle anything over $99.99, based on what you have shown. a more correct approach would be to not store the $ character in the table (it's a human convention and computers have no use for it) and store the prices as a decimal data type, i.e. just the 24.99 values would be stored. this will allow any value to work and work correctly when comparing values by magnitude. next to allow any (arbitrary) price ranges, you should have a database table that stores the ranges, one per row, with an id, the minimum value, the maximum value, and an optional display label (or you could use the min and max values to produce the display label - i.e. $0-$25.) you would join this table to your products table in a sql query to get the count of products for each range of prices. the id in this table would be used by the check box(s) to specify the range(s) to query for when displaying products. the query to display products would be similar to the joined query described above, except it would not have the count() and group by terms in it and it would limit the row(s) matched from the range table to the id's that were submitted from the checkbox(s)
-
in the first posted code, you are fetching a numerical array - $row = mysql_fetch_array($result, MYSQL_NUM);, so even if your sql query in that code was selecting the email field, it wouldn't be available using the associative name 'email'. in the last posted code, $_SESSION['user'] contains the numerically indexed array $row from your first posted code. $_SESSION['user'][0] would contain the name. so, if you don't expect the name value to ever get changed for anyone while they are logged in, change your first code to also select the name field in the sql query and use mysql_fetch_assoc() to fetch an associative array, where you could reference the ['name'] or ['email'] fields in your code using $_SESSION['user']['name'] or $_SESSION['user']['email'] finally, the mysql_ functions are depreciated, you should be switching to mysqli or PDO database functions.
-
the suggestions to put the connection lines inside the logic was just to prevent unnecessary database connections when things like search engines or bot scripts request the page using a request that's not from your ajax based search page. the delay symptom is consistent with the database server's disks not being configured to run continuously and you must wait for the disk to start and come up to speed before it can be accessed, though the delay would be more likely less than 10 seconds. the database server may be experiencing a more serious problem. in any case, you must find the actual cause of the problem before you can do anything to fix it. as to escaping string data, all string data being put into a sql query needs to be escaped to prevent any sql special characters from breaking the sql syntax, which also allows hackers to inject their own sql into your sql statement. for the php mysql_ functions, you would use mysql_real_escape_string() (and if you happen to be using an older version of php, you need to test if php is trying to escape the data and actually undo what php is doing before properly escaping the data yourself.) however, the mysql_ functions are now depreciated and you should be using msyqli or PDO functions (which will let you use prepared query statements that also prevent sql injection.)
-
i have reviewed your recent threads, this thread again, the code you posted above, and tried the page. it would seem this is the third thread since the start of this year where you have mentioned slow response times. do pages on your site that also depend on the database work as expected? is this only when searching via ajax? do you have more than one database server and this only occurs for one specific server? the only things i have to recommend at this time are - 1) add a page generation time calculation to the hotel search ajax.php page, using microtime(true), and log it to a file, along with the date/time, ip address, and the search value. you can then look at this log of information to both see if the problem is in getting the data from the database server or is elsewhere and if the problem only occurs after a period of inactivity. 2) the code has NO security against sql injection. the search string needs to be escaped before putting it into the sql query statement. also, since the purpose of hotel search ajax.php is to only service the ajax request, the database connection code should be inside the if($_POST) { ... } logic.
-
without any specific information to go by (i.e. profiling your site and profiling your code to find out exactly where the time is spent and how it changes between the first visit and follow on visits), this is just a general guess based on the symptom. your web server and/or database server may be either allowing the disk drives to come to a stop (in general, disk drives on servers run continuously) or they are not configured with a significantly long enough (in time) disk caching (query caching for the database server) so that the initial page request is always reading from the disk instead of from the disk cache/query cache. i did check your page - compareandchoose.com.au/newlook/hotel at pingdom.com - http://tools.pingdom.com/fpt/#!/xwShk/compareandchoose.com.au/newlook/hotel and the only serious thing that jumps out is your bg2.png image is 1.5mb, it's also apparently loaded via javascrpt and so doesn't even get requested until after the javascript library has been loaded and runs. this may not be relevant to your problem, but one of the times that i can recall a php application taking a huge amount of time on the first page load after a period of inactivity was for a shopping cart script that was built using a 'read everything regardless of it was even used' plugin method that literally included every possible/optional file in a collection of folders and was reading several hundred files (200+) every time a page was requested and when the content of these files was not in the disk cache, they had to be read from the disk.
-
the code setting $matchstring will also need to be changed (needs delimiters around the search pattern.) please post the line(s) immediately prior to line 141 that is/are defining $matchstring.
-
a) since the only information you provided is that your question is likely php related, i'm guessing you are asking about php frameworks, i.e. Laravel, Symfony2, CakePHP, etc? therefore, moving thread to that forum section... b) this question has been asked over and over and which framework you choose is largely based on your level of understanding and experience and is something you need to determine for yourself, through examining the documentation and trying the different frameworks to see which one is best for you and for the application you are making.
-
that particular line in the current download of the script is - if( $_POST['email'] && ereg( $matchstring, $_POST['email'] ) ) if this is what the op started with, you somehow removed the ['email'] parts when you changed from ereg() to preg_match()
-
the ctype_digit() function can be used to test if all the characters in a variable are numerical.
-
Is there an alternative to Header to redirect to another script
mac_gyver replied to rocky48's topic in PHP Coding Help
your goal would be to find and fix what is causing the error. based on where the output is being reported at, line 14 of questionnaire_connect.php, you likely have some white-space after the closing ?> tag in that file or something in questionnaire_connect.php is producing unexpected output. what is on line 14 questionnaire_connect.php? -
How to SELECT newly INSERTED row without having unique ID to reference
mac_gyver replied to BuildMyWeb's topic in MySQL Help
both the mysqli and pdo extensions have a last insert id method/function - http://www.php.net/manual/en/mysqli.insert-id.php or http://us1.php.net/manual/en/pdo.lastinsertid.php -
if your conx.php code is creating a new database connection, this is not the way to get a connection into your methods/class, because it is creating a new connection each time you call a class method and the connection is destroyed when the method ends/returns. as cyberRobot mentioned, your main code should create one instance of your database connection and pass it into the instance of your class, usually in the class constructor.
-
to hide your user's email addresses from each other, you need to put them into a bcc: field. by putting them all into the to: field, the entire list will be visible to everyone who receives the email (and anyone can then hit reply-all to spam all your members.) when using a bcc: field, you would use your own from: email address as the to: address. to make a list of email addresses, you would form a comma separated list. your current code only assigns one value over an over inside the while(){} loop, which would end up being the last value after the end of the while(){} loop.