cdoggg94 Posted July 5, 2012 Share Posted July 5, 2012 I am trying to get a search form's action to be a link that goes like this: MYSITE.com/cTrends/Agent/results.php?Details=78&findthis=jackson&submit=Search this is my form: <form id="form1" name="form1" method="get" action="results.php?Details=<?php echo $detnum ;?>"> //$detnum in this case is = 78.. <label> </label> <table border="0"> <tr> <td> <div align="center"><br /> <input name="findthis" type="text" id="findthis" size="15" /> <input type="submit" name="submit" id="submit" value="Search" /> </div></td> </tr> </table> </form> my problem is that the "?Details=78" will not display... any ideas why ? did I just do it wrong? or is it no possible? im a little confused because when i press submit, the search works fine and if i manually type in the Details part it works too, but it wont print it when I hit submit.. Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/ Share on other sites More sharing options...
Pikachu2000 Posted July 5, 2012 Share Posted July 5, 2012 If you look at the page source, you'll probably see that the ?details=78 isn't even in the action= attribute of the form. I haven't researched the technical explanation for that, but I'm sure it has something to do with using query string parameters when the form's method is get. You can use a hidden form field, or even a session variable for the value though. Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359218 Share on other sites More sharing options...
jbonnett Posted July 5, 2012 Share Posted July 5, 2012 Try somthing like this... <form class="search" method="get" action="search.php?Search"> <input type="text" name="Search" size="50" /> <a href="document.getElementById('search').submit('search')">Search</a> </form> Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359219 Share on other sites More sharing options...
cdoggg94 Posted July 5, 2012 Author Share Posted July 5, 2012 i have modified it to fit my code and doesnt seem to want to use the correct link..but thank you ! Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359221 Share on other sites More sharing options...
jbonnett Posted July 5, 2012 Share Posted July 5, 2012 Are you sure... if you type something in the search bar like your "78" it should redirect you to "search.php?Search=78" to get the url you want try... <form class="search" method="get" action="search.php?details=<? echo $detnum;?>&Search"> <input type="text" name="Search" size="50" /> <a href="document.getElementById('search').submit('search')">Search</a> </form> this will redirect you to the url if you typed is the search box "jackson" "search.php?details=78&search=jackson" Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359224 Share on other sites More sharing options...
cdoggg94 Posted July 5, 2012 Author Share Posted July 5, 2012 im probably doing it wrong haha..its been a long day... i am going to try again in the morning... i will let u know though! thanks again for the help ! much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359226 Share on other sites More sharing options...
jbonnett Posted July 5, 2012 Share Posted July 5, 2012 If you are doing a MySQL database search remember to do this for each $_GET $search = mysql_real_escape_string($_GET[search]); $details = mysql_real_escape_string($_GET[details]); then for example use RLIKE SELECT * FROM 'table' WHERE 'user' RLIKE '$search' OR 'id' RLIKE '$details' hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359227 Share on other sites More sharing options...
cdoggg94 Posted July 5, 2012 Author Share Posted July 5, 2012 my results looks like this from the form above... <?php $mysearch = $_GET['findthis']; //echo $mysearch; mysql_select_db($database_TrendConnect); $q = "SELECT * FROM Sheet1 WHERE pro_name LIKE '%" . mysql_real_escape_string($mysearch) . "%' OR lcbo_num LIKE '%" . mysql_real_escape_string($mysearch) . "%' ORDER BY pro_name ASC"; $mystuff = mysql_query($q); $num_rows = mysql_num_rows($mystuff); if($num_rows >= 1){ echo "<span class='Graphtitle'>There were ".$num_rows." results for your search!</span><br /><br />"; while($row = mysql_fetch_assoc($mystuff)) { echo "<table border='0'><tr><td>";?><a href="#" onClick="MyWindow=window.open('<?php echo "http://www.MYSITE.com/Agency/product3.php?Product=".$row['pro_id']; ?>','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=886'); return false;"><?php echo $row['pro_name']."</a> <span class='LTOlist'>".$row['F7']."</span><br /></td></tr></table>"; } } if($num_rows == 0){ echo "<span class='Graphtitle'>There were no results for your search</span>"; } ?> $findthis would be "$search" on your example...i dont know how or where to add the "details" part in it when i need it in the URL of this page...sorry if thats a really dumb thing to say...im a little confused Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359231 Share on other sites More sharing options...
jbonnett Posted July 5, 2012 Share Posted July 5, 2012 I don't know what your trying to accomplish with details and wouldn't it be easier to retrieve the details from the database anyway I edited your code... <?php $mysearch = mysql_real_escape_string($_GET['findthis']); //echo $mysearch; mysql_select_db($database_TrendConnect); $q = "SELECT * FROM Sheet1 WHERE pro_name RLIKE '$mysearch' OR lcbo_num RLIKE '$mysearch' ORDER BY pro_name ASC"; $mystuff = mysql_query($q); $num_rows = mysql_num_rows($mystuff); if($num_rows >= 1){ echo "<span class='Graphtitle'>There were ".$num_rows." results for your search!</span><br /><br />"; while($row = mysql_fetch_array($mystuff)) { echo "<table border='0'><tr><td>";?><a href="#" onClick="MyWindow=window.open('<?php echo "http://www.MYSITE.com/Agency/product3.php?Product=".$row['pro_id']; ?>','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=886'); return false;"><?php echo $row['pro_name']."</a> <span class='LTOlist'>".$row['F7']."</span><br /></td></tr></table>"; } }elseif($num_rows == 0){ echo "<span class='Graphtitle'>There were no results for your search</span>"; } ?> RLIKE means Regular expression LIKE so if you have the name jamie and jam in the database and you searched for jam the results will show both jamie and jam if you used the LIKE you would only get jam, and with LIKE it is case sensitive so if you searched Jam you would get no results Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359241 Share on other sites More sharing options...
cdoggg94 Posted July 5, 2012 Author Share Posted July 5, 2012 I am going to try that new code right now.... The details thing retrieves a clients information from a different table on the data base that I need to display, and when I'm done on the search page they would press back and I want to send back to the original page they were on... Thanks again for your help Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359283 Share on other sites More sharing options...
cdoggg94 Posted July 5, 2012 Author Share Posted July 5, 2012 I think that you are right though.. something like this should work : <form class="search" method="get" action="search.php?details=<? echo $detnum;?>&Search"> <input type="text" name="Search" size="50" /> <a href="document.getElementById('search').submit('search')">Search</a> </form> the only problem is that it doesnt use that as a link...i just looked up something and it wanted me to make a JS function and then give the <a id=""> the element from the function like this: <script type="text/javascript"> function changeLink() { document.getElementById('MyLink').innerHTML="Bookmark me!"; document.getElementById('MyLink').href="javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit()"; document.getElementById('MyLink').target="_blank"; } </script> <body onload changeLink();> <a id="MyLink" href="http://www.JustaLink.com">Just A Link</a> does that seem correct ? is so i can probably edit it to work for me... Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359287 Share on other sites More sharing options...
Pikachu2000 Posted July 5, 2012 Share Posted July 5, 2012 If you look at the page source, you'll probably see that the ?details=78 isn't even in the action= attribute of the form. I haven't researched the technical explanation for that, but I'm sure it has something to do with using query string parameters when the form's method is get. You can use a hidden form field, or even a session variable for the value though. Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359315 Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 What Pik is telling you, but you don't seem to understand, is: <form id="form1" name="form1" method="get" action="results.php"> //$detnum in this case is = 78.. <label> </label> <table border="0"> <tr> <td> <div align="center"><br /> <input name="Details" type="hidden" value="<?php echo $detnum ;?>" /> <input name="findthis" type="text" id="findthis" size="15" /> <input type="submit" name="submit" id="submit" value="Search" /> </div></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359318 Share on other sites More sharing options...
Pikachu2000 Posted July 5, 2012 Share Posted July 5, 2012 Not to mention that relying on JavaScript for something as basic as properly submitting a form is completely ludicrous. Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359322 Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 Nor the fact that the Javascript was written wrong, as there was no id for the element they were trying to get. Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359329 Share on other sites More sharing options...
cdoggg94 Posted July 5, 2012 Author Share Posted July 5, 2012 Well i have figured it out... <form id="form1" name="form1" method="get" action="results.php"> <label> </label> <table border="0"> <tr> <td> <div align="center"> <input type="hidden" name="Details" id="Details" value="<?php echo $detnum ;?>" /> <br /> <input name="findthis" type="text" id="findthis" size="15" /> <input type="submit" name="submit" id="submit" value="Search" /> </div></td> </tr> </table> </form> i took all the JS out. I think someone had said something about a hidden field and I went that way and it seems to work exactly how i want it to Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359336 Share on other sites More sharing options...
cdoggg94 Posted July 5, 2012 Author Share Posted July 5, 2012 I wish i would have seen jcbones post a while ago...but yea that works perfectly Quote Link to comment https://forums.phpfreaks.com/topic/265226-search-url/#findComment-1359339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.