PHP - Two Nearly Identical Pages Two Very Different Results
Ok, so I have grabbed a free template and attempted to put a dynamic table into one of the div's. I've got it to work on on my index.php, but I copied and pasted the entire code into member2.php and only changed the query and altered the table just a little bit For some reason though my table doesn't show up on the member2.php even though 90% of the code is the same.
Here are the pages and codes... http://www.royalfamilyhosting.com/test/index.php <div id="layoutBodyContent"> <h1>Aces Guild Donations Page </h1> <h2>Are you on top of your game? WE are!</h2> <?PHP require_once('./mylib.php'); $rank = 1; $olddate = strtotime(date("Y-m-d")); $newdate; $datecounter = 1; //connects to db dbconnect(); $query="SELECT name, date, SUM(amount) as total_money, SUM(bricks) as total_bricks FROM Aces_Donations GROUP BY Name ORDER BY total_money DESC, total_bricks DESC"; $result=mysql_query($query); //Opens the table echo "<table border = '3' width = 40% bgcolor=#A85045><caption><center>30 Day Rankings".'</center></caption>'; //Loop to run until eof while($row = mysql_fetch_array($result)){ //turns date into a comparable string $newdate = strtotime($row['date']); /*checks to see if date of new record matches date of previous record. If dates dont match the table is closed and a new table is opened for the new date. Rank is reset to reflect rankings for each specific date*/ if($newdate !== $olddate){ $olddate = $newdate; $datetracker++; if($datetracker == 30){ echo "<center><tr><td alignment = 'center'>".$rank."</td> <td alignment = 'center'>".$row['name']. "</td><td alignment = 'center'>". $row['total_money']."</td><td alignment= 'center'>".$row['total_bricks']."</tr></table></center>"; break; } } echo "<center><tr><td alignment = 'center'>".$rank."</td> <td alignment = 'center'>".$row['name']. "</td><td alignment = 'center'>". $row['total_money']."</td><td alignment= 'center'>".$row['total_bricks'].'</td></tr>'; echo '<br />'; $rank++; } echo '</table>'; ?> <br /><br /></p> </div> http://www.royalfamilyhosting.com/test/member2.php?member=Zneve08 <div id="layoutBodyContent"> <h1>Aces Guild Donations Page </h1> <h2>Are you on top of your game? WE are!</h2> <?PHP require_once('./mylib.php'); $membername = $_GET['member']; $rank = 1; $olddate = strtotime(date("Y-m-d")); $newdate; $datecounter = 1; //connects to db dbconnect(); $query = sprintf("SELECT * FROM `Aces_Donations` WHERE `name` = '%s'", $membername); //sets the results to a variable $result = mysql_query($query) or die(mysql_error()); //opens table, sets width, color, border and headers echo '<table bgcolor=#A85045 border = "3" width = 40%>'; echo "<tr><th alignment = 'center'>Member</th> <th alignment = 'center'>Amount</th><th alignment = 'center'>Date</th></tr>"; while($row = mysql_fetch_array($result)){ echo "<center><tr><td alignment = 'center'>".$row['name']. "</td><td alignment = 'center'>". $row['amount']."</td><td alignment = 'center'>".$row['date']."</td></tr></center>"; var_dump ($row['name']); var_dump ($row['amount']); echo "<br />"; } echo '</center></table>'; ?> <br /><br /></p> </div> I'm dying here and would love even shot in the dark at this point. The php code on member2.php works just fine when executed on its own page, so I don't really understand how this is happening. I put the var_dump in there just to make sure the data was being retrieved from the database, but the table should be positioned where the var_dump displays on the page Similar TutorialsWell, the title says it all, I do have a class named Database and one Users with multiple methods (code below). When i do try to use one user method (find_all) it returns 2 identical results from the database (and there is only one record in the DB). I tried to spot some mistake in the code but i couldn't find it, if you find something please tell... Database Class: Code: [Select] <?php /** * Class Name: MySQLDatabase * * Most of the methods in this class are * database-neutral methods for code reusability. * * Author: hisk */ require_once("config.php"); class MySQLDatabase { private $connection; private $last_query; private $magic_quotes_active; private $real_escape_string; function __construct() { $this->open_connection(); $this->magic_quotes_active = get_magic_quotes_gpc(); $this->real_escape_string = function_exists("mysql_real_escape_string"); } public function open_connection() { $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS); if(!$this->connection) { die("Database connection failed: " . mysql_error()); } else { $db_select = mysql_select_db(DB_NAME, $this->connection); if (!$db_select) { die("Database selection failed: " . mysql_error()); } } } public function close_connection() { if(isset($this->connection)) { mysql_close($this->connection); unset($this->connection); } } public function query($sql) { $this->last_query = $sql; $result = mysql_query($sql, $this->connection); $this->confirm_query($result); return $result; } private function confirm_query($result) { // usable only in query() function (private) if(!$result) { echo "DB Query Failed: " . mysql_error(); // The last query that might got us the problem echo "Last Query Was: " . $this->last_query; } } // agnostic public function num_rows($result) { return mysql_num_rows($result); } public function affected_rows($result) { return mysql_affected_rows($result); } public function insert_id($result) { return mysql_insert_id($result); } public function fetch_array($result) { return mysql_fetch_array($result); } public function escape_value($value) { if($this->real_escape_string) { // undo any magic quote effect so mysql_real_esc_str can work if($this->magic_quotes_active) { $value = stripslashes($value);} $value = mysql_real_escape_string($value); } else { if (!$this->magic_quotes_active) { $value = addslashes($value); } } return $value; } } $database = new MySQLDatabase(); ?> User Class: Code: [Select] <?php // smart to include the database class require_once("database.php"); class User { public static function find_by_id($id=0) { global $database; $result_set = self::find_by_sql("SELECT * FROM users WHERE id = {$id}"); $result = $database->fetch_array($result_set); return $result; } public static function find_all() { global $database; $result_set = self::find_by_sql("SELECT * FROM users"); return $result_set; } public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); return $result_set; } } ?> TEST FILE: Code: [Select] <?php require_once("../includes/database.php"); require_once("../includes/user.php"); $users = User::find_all(); $result = $database->fetch_array($users); foreach($result as $user) { echo "<pre>" . $user . "</pre>"; } ?> I've read through a few examples of how to paginate query results, but with my currently php skills I don't understand them, or they do not fit into my code. I wondered if I could make my own, and the logic behind this code makes sense to me, but it's still not working. Here is the code: <?php if (!$Start) { $Start = 0; } else { $Start=$_POST['Start']; } $crittercount = 120; $numpages = $crittercount / 30; $pagei = 1; $pagereit = 1; echo '<p><center> <FORM method=POST action=testpagination.php> <SELECT NAME="Start"> <OPTION>Page 1'; while ($pagereit < $numpages) { $pagei = $pagei + 30; echo '<OPTION value='.$pagei.'>'; $pagereit = $pagereit + 1; echo "Page: " .$pagereit; } echo '</SELECT>'; echo'<input type=submit value=Go></FORM><p>'; echo $Start; ?> The test site is he http://lab-lib.com/felishorns/Felishorns/websitetest/testpagination.php $crittercount is a variable that changes depending on the main $query. This query is invisible, and is used to pull a count for all the results in total. I am modifying it with $Start to create a second query which the viewer sees. $queryF = $query . " LIMIT " . $Start . ", 30"; The idea is that $Start changes depending on the value selected, thereby changing the query. In this test code, I've simply echoed the $Start value of that page, to see if the code is working, and it's not changing. What's wrong with this code? Is it not possible to have a form lead to the same link of the page it's on? Does the variable not become updated? Thanks in advance. Hello, Here's the weird thing, some of the pages shows the results, and some pages just won't show results at all, and I'm not getting any errors here is the one that doesn't Code: [Select] <? function display_mptt($user) { global $db; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id='25'"; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Users List</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE 'left' BETWEEN '".$row2['left']."' AND '".$row2['right']."' ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)or die(mysql_error())) { // only check stack if there is one $count = mysql_num_rows($result); if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title // add this node to the stack $var3 = '10'; echo "<table width='589' border='1'> <tr> <th>ID</th> <th>Name</th> </tr>"; echo "<tr><td><a href=\"user.php?id=".$row['id']."\">".$row['id']."</a></td>"; echo "<td>" . $row['title'] ." </td>"; echo "</tr>"; echo "</table>"; $right[] = $row['right']; } } display_mptt(1); ?> and here is the page that does Code: [Select] <? function display_mptt($user) { global $db; $id = $_GET['id']; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id= ".$id.""; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Your Tree</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE `left` BETWEEN ".$row2['left']." AND ".$row2['right']." ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)) { // only check stack if there is one if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title echo str_repeat(' ',count($right)).$row['title']."<br>"; // add this node to the stack $right[] = $row['right']; } } display_mptt(1); ?> Hello Everyone was wondering if I could get some help with the following code? I am querying a database for results of listings that are in a database these listings are displayed on the page in a form. I am wanting each listing to be on a different page. Below is my code. Code: [Select] $lim=1; if (!isset($s) || $s < 1 || !is_numeric($s)) { $s = 1; } $start = ($s - 1) * $lim; $sql = "select id,bussimg,imagewidth,imageheight,email,usridm,company,businesscategory,address1,address2,state,city,zip,website,email,repname,description,phonenumber,country,status from $approvecheckbusinesses where usridm='$user_id'"; $result=db_query($sql); $countpages = $sql; $sql = $sql . " order by id asc limit $start, $lim"; $result=db_query($sql); $pages = ceil(mysql_num_rows(mysql_query($countpages)) / $lim); $result=db_query($sql); for ($i = 0; $i < mysql_num_rows($result); $i++) { $Listid= mysql_result($result, $i, "id"); $usridm= mysql_result($result, $i, "usridm"); $CompanyName= mysql_result($result, $i, "company"); $realname= mysql_result($result, $i, "repname"); $email= mysql_result($result, $i, "email"); $BusinessCategory= mysql_result($result, $i, "businesscategory"); $status= mysql_result($result, $i, "status"); echo ("FORM IS TO BE DISPLAYED HERE"); } if ($pages > 1) { echo("<p align=left style='font-size: 85% color=white'>"); for ($i = 1; $i <= $pages; $i++) { echo("["); if ($i == $s) {echo("<b>");} else {echo("<a id=home_offerLink href='index.html?EditMemberListing&user_id=$user_id&s=$i'>");} echo("Page $i"); if ($i == $s) {echo("</b>");} else {echo("</a>");} echo("] "); } echo("</p>") Page Numbers here using the above code.. The problem I seem to be running into is that it only displats the first record. The page numbers show up page 1 page 3 page 2 and three are blank there is no mysql error or anything for some reason I only get that first result out of three Hello everyone, Very new to coding - enjoying it but struggling! I think I'm trying to do something pretty common but I seem to have come up against a complete wall now and after hours/days searching the internet and reading books I'm completely stuck! I'm trying to write some code to search a MySQL database of products, then display the results. For some search results there will be lots of products so I want to display 10 products on the first page then allow visitors to go to the next page to see another 10, and so on - a type of pagination, as they should then be able to click back to see the last page etc. I've got to the point of being able to display the first 10 search results, but I can't figure out at all how to create some kind of page scrolling/pagination system. Please, does anybody have any ideas?? I've attached my code, I hope this is the correct way of doing things here. Many thanks for your time! The PHP search code... Code: [Select] <?php //opens connection to mysql server $dbc = mysql_connect('localhost'); if (!$dbc) { die('Not connected :' . mysql_error()); } echo "Connected to mysql database<br />"; //select database $db_selected = mysql_select_db("NAME_OF_DATABASE", $dbc); if (!$db_selected) { die ("Cannot connect :" . mysql_error()); } echo "Connected to database<br /><hr />"; echo "Here are your results"; $term = $_POST['term']; $category = $_POST['category']; $brand = $_POST['brand_name']; $sql = mysql_query("SELECT * FROM products where product_name like '%$term%' AND category_name like '%$category%' AND brand_name like '%$brand%' LIMIT 0, 10"); { while ($row = mysql_fetch_array($sql)){ echo "<table border='1' width='100%'> "; echo "<tr>"; echo "<td style='vertical-align:top' width='25%'>" . '<img src="', $row['image_url'], '" alt="', $row['product_name'], '" width="100" height="100" />' . "</td>"; echo "<td style='vertical-align:top' width='50%'>" . $row['product_name']; echo "<br />"; echo "<span style='font-size: 10px'>" . $row['description'] . "</span>" . "</td>"; echo "<td style='vertical-align:top' width='25%'>" . $row['price']; echo "<br />"; echo "<br />"; echo "<hr />"; echo "$row['merchant_name'] </td>"; echo "</tr>"; } echo "</table>"; } ?> Hi, my page is currently up at brewhas.org/transactions.php. When I retrieve a set of results > the defined # per page (such as entering 'WI' for last name), I see the first page correctly, and see the links to next pages, but when I go to the next page there are no results displayed. Same for p.3, etc. So I've looked around enough to know that I need to pass a variable to the subsequent pages, either via a session variable or the URL. I have 2 fields input on the form, as well as a limit and offset. My questions are 1) do I need to pass all 4 and if so then should I use a session variable so the URL does not get too long, and 2) can anyone provide any help with setting session variables and including them to be passed? I'm a newbie and have grabbed some code where I can but this is where i'm stuck. thanks in advance. Code: [Select] <?php include 'config.php'; include 'opendb.php'; $rows_per_page = 20; //Get the values from the text boxes $fnamesearch = $_POST["fnamesearch"]; $lnamesearch = $_POST["lnamesearch"]; //These trim and convert the name fields to upper case. $fnamesearch=strtoupper($fnamesearch); $lnamesearch=strtoupper($lnamesearch); $fnamesearch=trim($fnamesearch); $lnamesearch=trim($lnamesearch); // Count how many rows are coming back for the query //This checks to see if there are at least 2 chars in the last name. if (strlen($lnamesearch)<2) { echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>"; exit; } else //sets the query to get the number of rows { $query = "SELECT COUNT(*) FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%'))"; } $result = mysql_query($query) or die ("Could not execute the query"); //executes the get count query $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; echo "count: ".$numrows; $lastpage = ceil($numrows/$rows_per_page); //determines how many pages based on rows divided by rows per page echo "pages: ".$lastpage; // Get required page number. If not present, default to 1. if (isset($_GET['pageno']) && is_numeric($_GET['pageno'])) {$pageno = $_GET['pageno']; } else {$pageno = 1; } //Checks that the value of $pageno is an integer between 1 and $lastpage. $pageno = (int)$pageno; if ($pageno > $lastpage) {$pageno = $lastpage; } if ($pageno < 1) {$pageno = 1; } //constructs OFFSET for the sql SELECT statement $offset = ($pageno - 1) * $rows_per_page; //This checks to see if there are at least 2 chars in the last name. if (strlen($lnamesearch)<2) { echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>"; exit; } else //sets the query to get the number of rows { $query = "SELECT * FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%')) LIMIT $offset, $rows_per_page"; } $result = mysql_query($query) or die ("Could not execute the query"); //executes the query //Count the number of results $numrows=mysql_num_rows($result); echo "<p class='style7'>Your search: "".$fnamesearch." ".$lnamesearch."" returned <b>".$numrows."</b> results.</p>"; if ($numrows == 0) //if no matches, don't display the table exit; else //build the table and insert rows { echo "<table border=1 cellspacing=0 cellpadding=1 width='77%' align=left bordercolor=#666666>"; echo "<tr bgcolor=#cccc99 class='style5'><th width='10%' class='style5'>Date</th>"; echo "<th width='10%' class='style5'>Action</th>"; echo "<th width='12%' class='style5'>From</th>"; echo "<th width='12%' class='style5'>To</th>"; echo "<th width='5%' class='style5'>Pos</th>"; echo "<th width='18%' class='style5'>Name</th>"; echo "<th width='5%' class='style5'>Round</th></tr>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td width='10%' class='style6'>".$row['TRANS_DT']."</td>"; echo "<td width='10%' class='style6'>".$row['TRANS_ACTION']."</td>"; echo "<td width='12%' class='style6'>".$row['FROM_OWNER']."</td>"; echo "<td width='12%' class='style6'>".$row['TO_OWNER']."</td>"; echo "<td width='5%' class='style6'>".$row['POSITION']."</td>"; echo "<td width='18%' class='style6'>".$row['PLAYER_FNAME']." ".$row['PLAYER_LNAME']."</td>"; echo "<td width='5%' class='style6'>".$row['DRAFT_RND']."</td></tr>"; } /****** build the pagination links ******/ // if not on page 1, don't show back links if ($pageno > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'><<</a> "; // get previous page num $prevpage = $pageno - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'><</a> "; } // range of num links to show $range = 3; // loop to show links to range of pages around current page for ($x = ($pageno - $range); $x < (($pageno + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $lastpage)) { // if we're on current page... if ($x == $pageno) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$x'>$x</a> "; } // end else } // end if } // if not on last page, show forward and last page links if ($pageno != $lastpage) { // get next page $nextpage = $pageno + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>>></a> "; } // end if /****** end build pagination links ******/ echo "</table>"; } mysql_free_result($result); //release the result set from the table mysql_close($conn); //close the connection to the db ?> MOD EDIT: [code] . . . [/code] tags added. Need help to correct my cording! I want to limited search results by 5 items on one page.
Don't know how correctly to add limit: "limit $page1,5".
When I add it: $sql = "SELECT * FROM data GROUP BY city ORDER BY city limit $page1,5";
it doesn't limit searching result by pages.
Attached Files
search3.php 1.67KB
5 downloads In the code below, I am trying to produce a google-like page where the user can type keywords and pages of search results are displayed. The main difficulty I am encountering is that when the browser changes pages, it forgets everything about current data. Perhaps I should include the display of pages inside the HTML form ? How can I fix this code ? Here is the contents of my searchpage.php file : <?php $keywords=''; $display_search_results=''; if(isset($_POST['search_submitted'])) { $keywords=$_POST['keywords']; $search_results=array(); $totalNbrOfItems=20; for($k=1;$k<=$totalNbrOfItems;$k++) { $search_results[$k]='Your keywords '$keyowrds.' have been found in item number '.$k; } $nbrOfItemsParPage = 5; $nbrOfPages = ceil($totalNbrOfItems / $nbrOfItemsParPage); // Compute current page $current_page = (isset($_GET['page']))?intval($_GET['page']):1; $display_pages=($nbrOfPages<2)?'<p>Page : ':'<p>Pages : '; for ($i = 1 ; $i <= $nbrOfPages ; $i++) { if ($i == $current_page) //No link to the current page { $display_pages=$display_pages.$i.' '; } else { $display_pages=$display_pages.'<a href="searchpage.php?'. 'page='.$i.'">'. $i . '</a> '; } } $display_pages=$display_pages.'</p>'; $display_items=''; $start=$nbrOfItemsPerPage*($current_page-1); for($k=1;$k<=$nbrOfItemsParPage;$k++) { $display_items=$display_items.($search_results[$start+$k]).'<br>'; } $display_search_results=$display_pages.$display_items; } echo '<form method="post" action="searchpage.php">'. ' Type your keywords here : <br><br>'. '<textarea cols="65" rows="1" '. 'id="keywords_id" name="keywords">'.$keywords.'</textarea>'. '<input type="submit" name="search_submitted" id="search_submitted_id" value="Search" /> '. '</fieldset>'. '</form>'; echo $display_search_results; ?> When a file is uploaded, I wish to determine whether an existing identical file (regardless of what it is named or what extension it has) already exists and if so don't save the newly uploaded file but just point it to the existing one. My primary reason for doing so is not really to save hard drive space but to be able to manage duplicate documents. One option is to store a hash of the documents in the DB and when a new document is uploaded, query the DB to see if an identical hash exists. How certain can one be that two hashes will never be duplicated? Another option is to compare the byte stream. For this, I would first query the DB to see if a file with same size and media type exists, and then compare the document to all existing files which have that same criteria. Or many some other approach? Recommendations? Thanks
<?php error_reporting(E_ALL); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); function compareFilesTest(string $file_a, string $file_b) { $time = microtime(true); display($time, $file_a, $file_b, 'compareFilesTest', compareFiles($file_a, $file_b)); } function compareFilesTest2(string $file_a, string $file_b) { $time = microtime(true); display($time, $file_a, $file_b, 'compareFilesTest2', identical($file_a, $file_b)); } function compareFilesHashTest(string $file_a, string $file_b, string $algo = 'md5') { $time = microtime(true); display($time, $file_a, $file_b, 'compareFilesHashTest', hash_file($algo, $file_a)===hash_file($algo, $file_b), $algo); } function display(float $time, string $file_a, string $file_b, string $test, bool $status, string $algorithm=null) { printf("\n%s\nFile1: %s\nFile2: %s\nStatus: %s\nTime (uS): %d\n", $test.($algorithm?" ($algorithm)":''), $file_a, $file_b, $status?'EQUAL':'NOT EQUAL', 1000000*(microtime(true) - $time)); } function compareFiles(string $file_a, string $file_b):bool { if (filesize($file_a) == filesize($file_b)) { $fp_a = fopen($file_a, 'rb'); $fp_b = fopen($file_b, 'rb'); while (!feof($fp_a) && ($b = fread($fp_a, 4096)) !== false) { $b_b = fread($fp_b, 4096); if ($b !== $b_b) { fclose($fp_a); fclose($fp_b); return false; } } fclose($fp_a); fclose($fp_b); return true; } return false; } function identical($fileOne, $fileTwo) { if (filetype($fileOne) !== filetype($fileTwo)) return false; if (filesize($fileOne) !== filesize($fileTwo)) return false; if (! $fp1 = fopen($fileOne, 'rb')) return false; if (! $fp2 = fopen($fileTwo, 'rb')) { fclose($fp1); return false; } $same = true; while (! feof($fp1) and ! feof($fp2)) if (fread($fp1, 4096) !== fread($fp2, 4096)) { $same = false; break; } if (feof($fp1) !== feof($fp2)) $same = false; fclose($fp1); fclose($fp2); return $same; } $path = __DIR__.'/test_documents/'; //print_r(hash_algos()); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpg'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c1c96440_MasterFormat-2016.pdf'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'x602a9c07af00c_IMG_1225.jpg'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpgx'); compareFilesHashTest($path.'file1.txt', $path.'file2.md'); compareFilesHashTest($path.'file1.txt', $path.'file3.txt'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpg', 'sha256'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c1c96440_MasterFormat-2016.pdf', 'sha256'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'x602a9c07af00c_IMG_1225.jpg', 'sha256'); compareFilesHashTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpgx', 'sha256'); compareFilesHashTest($path.'file1.txt', $path.'file2.md', 'sha256'); compareFilesHashTest($path.'file1.txt', $path.'file3.txt', 'sha256'); compareFilesTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpg'); compareFilesTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c1c96440_MasterFormat-2016.pdf'); compareFilesTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'x602a9c07af00c_IMG_1225.jpg'); compareFilesTest($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpgx'); compareFilesTest($path.'file1.txt', $path.'file2.md'); compareFilesTest($path.'file1.txt', $path.'file3.txt'); compareFilesTest2($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpg'); compareFilesTest2($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c1c96440_MasterFormat-2016.pdf'); compareFilesTest2($path.'602a9c07af00c_IMG_1225.jpg', $path.'x602a9c07af00c_IMG_1225.jpg'); compareFilesTest2($path.'602a9c07af00c_IMG_1225.jpg', $path.'602a9c07af00c_IMG_1225.jpgx'); compareFilesTest2($path.'file1.txt', $path.'file2.md'); compareFilesTest2($path.'file1.txt', $path.'file3.txt');
Hello, Experts! Need you advice. Here is the code: <?php if ($var == "") { echo "text"; } if ($var == "*") { echo "text"; } else if ($var != "") { $query = "SELECT * FROM bd WHERE ....."; $data = mysql_query($query) or die(mysql_error()); $anymatches=mysql_num_rows($data); if ($anymatches != 0) { echo "text"; while($row = mysql_fetch_array($data)) { echo "text"; } } if ($anymatches == 0) { $query2 = "SELECT * FROM bd WHERE....."; $data2 = mysql_query($query2) or die(mysql_error()); $anymatches2=mysql_num_rows($data2); if ($anymatches2 != 0) { echo "text" else { mysql_query("INSERT INTO notfound (notfound) VALUES ('$var')") or die(mysql_error()); } } } ?> The last line adds two identical lines to my table. Do I run it twice? Thanks in advance! I'm surely doing something wrong here, but I just cannot see it. Any assistance will be greatly appreciated. In a login script I read the following two variables from an SQL database. Both fields are defined as int. $this->ScheduleA = $rs->fetchCol('ScheduleA'); $this->SchedConst = $rs->fetchCol('SchedConstant'); Later, I retrieve these variables and attempt to compare them. $schA = $sess['ScheduleA']; $schC = $sess['SchedConst']; if ($schA == $schC) { require('Testing.php'); } else { require('NotAllowed.php'); } They never compare as equal, even though they contain the same value. What, pray tell, am I missing? Trying to create a very simple API script sending XML data. When I send the "hard coded" XML, it works perfectly. When I add a form to supply the data for the XML, I get a 500 Internal Server error. Have tried it on two different servers. No error in the logs. Stumped. Examples below are VERY simplified (and obviously won't do anything as-is) to show what I'm dealing with. This one works fine: <?php $xml = "<Order><UserId>foo</UserId><Password>foo</Password><Mode>Test</Mode><Name>Charles R. Hodges</Name>"; $xml .= "</Order>"; $url = 'http://sitename.com'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($response); print_r($xml); ?> And then I use this one and all heck breaks loose with the 500 Internal Error: <?php if (isset($_POST['submit'])) { $xml = "<Order><UserId>foo</UserId><Password>foo</Password><Mode>Test</Mode><Name>{$_POST['name']}</Name>"; $xml .= "</Order>"; $url = 'http://sitename.com'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($response); print_r($xml); exit; } ?> <html>... etc <form method="post" action=""> Name: <input type="text" name="name" /> <p><input type="submit" name="submit" "Add to XML string and send" /> </form> ?>
So on a cloud computing platform such as AWS, how would one keep the /html folder in Apache identical?
I can FTP into one "instance" and modify code easily enough, but how would I push reversions to multiple servers at once?
It seems like such a simple question, but the answer eludes me.
Edited by arbitrageur, 20 November 2014 - 04:43 PM. I am building online dictionary with php. The following code allows the user to search a word and display the definition results from the database. The problem is the user has to input the identical words only. If the words are not exactly similar to the database words it returns error message. But in this case I need it to give a suggestion along with the error message based on the few beginning words of the submitted word. eg. if the user type a word "suggestion", and the word "suggestion" is not available in the database .... instead of just the error message to also search and include other stored data closer to the submitted word ... like "TRY the word SUGGEST". can any one help me on this please. Thank you in advance. here is the code Code: [Select] <?php $script = $_SERVER['PHP_SELF']; if(isset($_POST['sbm']) && isset($_POST['word']) ) { submited(); } else { show_form(); } function show_form() { ?> <p><center> Type <span style='font-weight:bold;'>ENGLISH</span> word Only! <span style='font-weight:bold;'>SPELL IT CORRECTLY!!!.</span></center></P> <p><center>Search</center></p> <center><form name=frm method=POST action="<?php echo $script ?>"> <p><input type=text name="word"><br /></p> <p><input type=submit name="sbm" value="Submit"> </form> </center></p> <?php } function submited() { require("dbconn.inc"); $word=$_POST['word']; $sql="select * from words where eng like '".mysql_real_escape_string($word)."'"; $result=mysql_query($sql,$link); // I assume $link is defined in dbconn.inc if(@mysql_num_rows($result)!=0) { $rows=mysql_fetch_array($result); $am=$rows["am"]; echo("<center>The Word <h1><b>$word</b></h1> in Am is : <h1><b>$am </b></h1><br></center>"); } else { echo("<center><span style='font-weight:bold;color:#FF0000;'>Could not find it! Check the spelling and try again !!</span></center>"); } // The connection will close automatically since // this is near the end of the script. mysql_close($link); show_form(); } ?> like if I'm displaying a hundred entries , my website will be super long in length so I wanna break those hundred entries into maybe like 12 per page . Then click next page or the page number to view the next 12. Hi, I am looking for reliable, effective code to cache one or two of my website webpages. I know there are packages like the pear cache lite but is far beyond my needs and complex in terms of never used pear before etc. I am looking for a good cache class perhaps or a link to a good cache script. Does anyone have any code they would like to share or know of any good cache classes etc? I want to keep it relatively simple if possible. Thanks for any suggestions, help. PHPLOVER hi guy's i have on one page select from table, and i don't know how to limit showing content from database on 3, and rest to make number under it and when i click on that number next 3 is showen? Something like on forum when you have more topics then you can show, on botom of page are showen numbers (links). Can some explain me how to do this? i put in while loop something like this Code: [Select] while ($prom = mysql_fetch_object($res) and $i<3) and now it is limited on showing first 3, my problem is showing next 3, and if there is more how to split it on 3 per page? Hello everyone, I am new to this site and new to working with php. I am wondering about a code that i could use for splash pages for members to be able to use them. I have the splash pages set up already but have not been able to figure out how to code it so that all the members of the site can use them to promote the site. Any help would be great thanks. Aaron Hello, I was wondering if someone could help me to "get" the webaddress of a current webpage and then pull off pieces of the page. All of my pages look like: http://localhost:8888/algebra_book/Chapters/Quadratic_Functions/introductory_problem.php BUT, the stuff to the left of Quadratic Functions WILL change in the future. So all will look like: *Quadratic_Functions/introductory_problem.php Then, I'd like to pull off a $chapter variable, which in this case is Quadratic_Functions and a $page_name variable which in this case will be introductory_problem. Thanks so much. Hey, i was wondering if anyone knew how i could make a script so when i register a new account... There will be made a link in members.php and when you go there you see the new registered (and the old ones) name... And once you click it you get into their page (their page should be created when registering a new account). Im pretty blank how to do it so ill ask you guys :/ |