PHP - Moved: Pre-search Post To Self Without Page Reload...
This topic has been moved to Ajax Help.
http://www.phpfreaks.com/forums/index.php?topic=346243.0 Similar TutorialsHello I have this code that searches multiple tables. running this query in the phpmyadmin page works fine and gives correct results. I echo-ed the $kw and noticed that it is lost (empty) when I click on Next (when moving to the second page or so..) How do I save the $kw for all search results? Thank you so much $kw = trim($_POST['keyword']); $kw = mysql_real_escape_string($kw); //Nomber of rows to display per page $page_rows=20; //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } echo "$kw of $pagenum"; //Count we count the number of results $data = mysql_query(" SELECT `id`,`title`, `body`, 'condoms_en' as REF FROM `condoms_en` where `title` like '%$kw%' OR `body` like '%$kw%' UNION SELECT `id`,`title`, `body`, 'discr_en' as REF FROM `discr_en` where `title` like '%$kw%' OR `body` like '%$kw%' UNION SELECT `id`,`title`, `body`, 'diseases_en' as REF FROM `diseases_en` where `title` like '%$kw%' OR `body` like '%$kw%' UNION SELECT `id`,`title`, `body`, 'express_en' as REF FROM `express_en` where `title` like '%$kw%' OR `body` like '%$kw%' ") or die(mysql_error()); $rows = mysql_num_rows($data); if ($rows ==1 || $rows > 1) { //echo "Number of rows $rows <br/>"; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //echo "<h4>".$pagenum."-20 of ".$total."results</h4> <br />"; // This shows the user what page they are on, and the total number of pages echo " ===> Page $pagenum of $last <br/><br/>"; //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it $data_p = mysql_query(" SELECT `id`,`title`, `body`, 'condoms_en' as REF FROM `condoms_en` where `title` like '%$kw%' OR `body` like '%$kw%' UNION SELECT `id`,`title`, `body`, 'discr_en' as REF FROM `discr_en` where `title` like '%$kw%' OR `body` like '%$kw%' UNION SELECT `id`,`title`, `body`, 'diseases_en' as REF FROM `diseases_en` where `title` like '%$kw%' OR `body` like '%$kw%' UNION SELECT `id`,`title`, `body`, 'express_en' as REF FROM `express_en` where `title` like '%$kw%' OR `body` like '%$kw%' $max") or die(mysql_error()); //This is where you display your query results while($info = mysql_fetch_array( $data_p )) { print $info['title']; //print $info['REF']; echo "<br>"; } echo "<p><br/>"; // First we check if we are on page one. If we are then we don't need a link to the previous page //or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. if ($pagenum == 1) { } else { echo " <a style=\"color: #FF0000\" href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a style=\"color: #FF0000\" href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } //just a spacer echo " ---- "; //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a style=\"color: #FF0000\" href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a style=\"color: #FF0000\" href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } } //results was found else { echo "No results FOUND"; } This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=343888.0 The result pages is supposed to have pagination like google help me please
hello guys, i have a question, in some php files i have in the start <? ob_start(); ?> <?php session_start(); ........ ..... ...... if(isset($_POST['sub_1'])) { $_SESSION['address_tmp']=$_SESSION['address_tmp']." oK "; header("location:some_other_page.php#jumpselection"); } if(isset($_POST['sub_2'])) { $_SESSION['address2_tmp']=$_SESSION['address2_tmp']." hello "; header("location:thispage.php#jumpselection"); } ?> <body> <form method="post" action=""> <input type="Submit" name="sub_1" value="action1"style="height:3.9em; width:16.5em; font-size:95%;"> </form> </body> <body> <form method="post" action=""> <input type="Submit" name="sub_2" value="action2"style="height:3.9em; width:16.5em; font-size:95%;"> </form> </body> <? ob_end_flush(); ?> but every page have 10-15 buttons every button in the end reloads the same page with header("location:thispage.php#jumpselection"); or cals another page with header("location:some_other_page.php#jumpselection"); this works but i notise some lag on the bowser afrer while.. I would like the page orderform.php to reload or refresh to normal after I click this link: this is what i have and this link is on a different page though... if($myError==true) echo "<br /><br />Click here to <a href='orderform.php?nocache='.time().'>go back...</a>"; else header("location: orderform.php"); I have an html table that is being populated with links from a specific directory.. I would like the user to be able to click the link and if its a file they will download the file. If its a directory, I woudl like to reload the current page but this time show the contents of the directory. My main issue is that I have a session variable called 'workingdirectory' that I need to update before I reload the page. I have tried setting it and then calling Location('page.php') but I get the 'cannot change header information' error. I realized I was getting this because I had begun to call HTML code before the PHP was finished. Is there a way to just simply update the session variable, and then make the page reload when the user clicks on a link? Hello dear friends, I've very annoying problem my website is for child drawing (draw.php) after child do drawing will click on submit (form) by sending it to another page (thanks.php) | | | | data will be submitted to database and gives message saying ( thank you for ...blah blah blah) here is the problem if he refresh the page , it will also add entry to the database so imagine if someone did many many refresh, i will get many many empty entry into database how to stop this ? here is simple code based on this problem Code: [Select] <form name="frm" method="post" action="thanks.php"> <input type="text" name="name" id="name" value=""> <input type="text" name="email" id="email" value=""> <button type="submit">Submit</button> </form> and the (thanks.php) file code *assume we have connection to db Code: [Select] $sql = "INSERT INTO $table (name, email) VALUES ('$name', '$email')"; mysql_query($sql, $conn) or die(mysql_error()); echo "Thank you kid..nice drawing"; now my problem if (thanks.php) got refreshed it will also will add empty entry to database can anyone please help me how to stop it. Hello, I am having issues with getting cookies to function how i'd like them to. My goal is to be able to capture a cookie value from the url if a user comes to my site via something like adwords. An example URL they could come to is http://www.mysite.com?kw=hello I am trying to capture the word 'hello' and tie it to that visitor regardless of where they go on the site. I need to use that value to pass through if they complete a form on my site so that i can track the keyword source. I have included the following as the first line of code on every page of my site: Code: [Select] $kw = $_GET["kw"]; setcookie('kw',$kw); Then, if i go to this url: http://www.mysite.com?kw=hello and then later go to a url like this: http://www.mysite.com/page1.html, i am able to echo out the cookie on page1.html using the following code which is contained in page1.html: Code: [Select] echo $_COOKIE["kw"]; The problem is, if i then refresh page1.html i can no longer echo out the cookie--it disappears. I need the cookie to stay with the user no matter what page they are on within the site and not matter how many different pages they visit. I hope i am explaining myself in a way someone can understand. Perhaps cookies aren't the best way? Should i use sessions instead? Thanks in advance for your help The Script:
<h1>Do Add a Message to the MySQL Database</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <textarea name="message"></textarea> <br/> <input type="submit" name="submit"/> </form> <?php // The Connection to the Database // Taken Out ?> <?php // To insert the text data into the MySQL database. if(isset($_POST['submit'])){ $tqs = "INSERT INTO messages (`message`) VALUES ('{$_POST['message']}')"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); } ?> <?php // To select the text data from the MySQL database. $tqs = "SELECT * FROM messages"; $tqr = mysqli_query($dbc, $tqs); // To print out the text data inside of table on the page. echo "<h1>This Is Where the Messages Gets Printed on Screen</h1>"; echo "<table><tr><td>ID</td><td>The Message</td></tr>"; while($row = mysqli_fetch_assoc($tqr)){ echo "<tr><td>" . $row['id'] . "</td><td>" . $row['message'] . "</td></tr>"; } echo "</table>"; ?>1. When I have added text with the form to the MySQL database... 2. ... and I have clicked on "page reload" in Firefox to reload the page... 3. ... then the before submitted text gets submitted again to the MySQL database. So basically, add text with the form to the MySQL database, reload the page in Firefox, and the before added text will get submitted to the MySQL database again. My Question Is: What is the proper way to avoid this? Edited by glassfish, 06 October 2014 - 10:18 AM. //here is the code. For some reason it searches the first time, but the second search loads everything. testing at: mnmotorsports.com // searcha.php <?php require("head.php");?> <table width="800" border="1"><tr><td width="550"></td><td> <form method="post" action="searcha.php?go" id="searchform"> <input type="text" name="name"> <input type="submit" name="submit" value="Search"> </form> </td></tr> <tr><td height ="300"> <?php echo "searching"; // connect to host require("connect.php"); // retrieve data $name = $_POST['name']; echo " any card name matching: <b>'".$name."'</b>"; $query = "SELECT * FROM ".$tname." WHERE name LIKE '%".$name."%'"; $result = mysql_query($query) or die(mysql_error()); $SearchCntr=0; while($row = mysql_fetch_array($result)){ $SearchCntr++; echo "<table border='1' width='500'>"; echo "<tr><td>".$row['edition']." | <a href='#'>".$row['name']."</a> | ".$row['manacost']." | ".$row['price']."</td></tr>"; echo "</table>"; } echo $SearchCntr." SEARCH RESULTS</body></html>"; ?> </td><td></td> </tr> </table> <?php require("footer.php"); ?> Hi, I have a form for news articles. It has a title and a body which is fine. I also have a search box that allows the user to search for a memeber and click their name when it appears. This moves a div with a data-id into another div. The purpose of this is to tag them in the article. I am able to post all of the simple stuff but how would i post these value. I am assuming that i would need to create an array of said values but i am struggling to get them showing in post at all. Here is the code i have so far <?php function searchForPeople($searchVal, $exclude = '0'){ $sv1 = $searchVal; $sv2 = $searchVal; include 'includes/dbconn.php'; $out =""; $stmt = $conn -> prepare(" SELECT fname, lname, id FROM person WHERE id NOT IN (".implode(',', array_map('intval', $exclude)).") AND (fname LIKE CONCAT('%',?,'%') OR lname LIKE CONCAT('%',?,'%')) "); $stmt -> bind_param('ss', $sv1, $sv2); $stmt -> execute(); $stmt -> bind_result($fn, $ln, $pid); while($stmt -> fetch()){ $out .= "<div class='btn btn-primary m-1 tagInArticle' name='taggedPerson[]' data-id='$pid'>$fn $ln</div>"; } return $out; } ?> ...... <div id="searchResultsHere"> <!-- ajax content here --> </div> <hr> <div id="taggedInArticleContainer"> <!-- ajax content here --> </div> ....... <div class="col-lg-2"> <button type="submit" name="PublishNewNews" class="btn btn-primary w-100 mb-3">Publish</button> <button class="btn btn-primary w-100">Save</button> <hr> <div class="btn btn-warning w-100 mb-3">Private</div> <input type="hidden" name="howVisible" value="Private"> <hr> <p class="text-justify">Private news articles will only be avilable to logged in users</p> </div> ....... <script> $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); tagButton.appendTo('#taggedInArticleContainer') }); $('#searchForPeopleBox').keyup(function(){ var searchVal = $(this).val() var tagged = '0' var tagged = $('#taggedInArticleContainer').find('.tagInArticle').map(function(){ return $(this).data('id'); }).get(); $.ajax({ type: 'post', data: {"ajax" : 'one', "val" : searchVal, "exclude" : tagged}, success: function(resp){ $('#searchResultsHere').html(resp) } }) }); </script> I hope this is enough to go on. I am sure it is simple but i just cant get it. Thanks all in advance. Some code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? Hi, i'm currently building essentially an API for my URL shortener site so other sites can implement it. But i've hit a stumbling block on the last script of the lot(the others merely collate the data and store it) In this last script, i need to find all this data, stored in cookies and inout it into the database, as the main site does(i'm confident this bit works, as it's the code from the main site just copied across, and i can see the data in the database). Importantly, i then need o look in another table for the callback URL to send the data back to $urltoshorten = $_COOKIE["URLtoShorten"]; $alias = $_COOKIE["urlalias"]; $key = $_COOKIE["key"]; //connection details go in here $alias =mysql_real_escape_string($alias); $urltoshorten = mysql_real_escape_string($urltoshorten); $base = "http://s-url.co.uk/i/?id="; $url = $base . $alias ; //this is the main bit, where the URL shortening occurs mysql_query("INSERT INTO table (id, name) VALUES('$alias', '$urltoshorten')")or die( mysql_error()); //this is where the callback url is looked for $result= mysql_query("SELECT apiaddress FROM apistuff WHERE apinumber='$key'")or die( mysql_error()); $row = mysql_fetch_array($result); $new = $row[apiaddress]; //I then start a CURL session to POST data to the page in question, as found above $Curl_Session = curl_init($new); curl_setopt ($Curl_Session, CURLOPT_POST, 1); curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "shortenedurl=$url"); curl_exec ($Curl_Session); curl_close ($Curl_Session); annoyingly, no errors get thrown, as far as i can see, i just end at a blank page without being returned to the callback page. I'm rather stumped on this one, where am i likely to be going wrong/how do i go about correcting it. Cheers Joe This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=353240.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=307126.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348057.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349304.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=342166.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=333014.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348171.0 |