TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-04-2010, 07:15 PM   #1 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Book Having problem with quotes in php

Hello, I have a search script, it does these

$ismial1 = $_REQUEST['search'];
$ismial1 = strip_tags($ismial1);
$ismial1 = htmlspecialchars($ismial1);
$ismial1 = htmlentities($ismial1);
$ismial1 = trim($ismial1);

but when user search something like this with quotes

James o"keefe

it get the search title like = James o\"keefe
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 02-04-2010, 08:27 PM   #2 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Default

I solved problem by myself ;) here is the solution.

PHP Code:
$ismial1 trim(htmlspecialchars(strip_tags($_REQUEST['title'])));

if (
get_magic_quotes_gpc()) {

$ismial1 stripcslashes($ismial1);


__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 02-05-2010, 05:15 AM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Awesome, thanks for replying with the solution so others may learn form it.
__________________

Village Idiot is offline  
Reply With Quote
Old 02-25-2010, 07:58 PM   #4 (permalink)
The Wanderer
 
Join Date: Feb 2010
Posts: 5
Thanks: 0
Aiahoos is on a distinguished road
Default

Oh. You use such a simple script. I had to look for hundreds php tutorials to create PHP/MySQL search engine with search keywords displayed in bold
PHP Code:
< ?php  

002 $hostname_logon 
"localhost" ;     

003 $database_logon "databaseName" ;    

004 $username_logon "databaseUser" ;    

005 $password_logon "databasePass" ;     

006 //open database connection  

007  $connections mysql_connect($hostname_logon$username_logon$password_logon) or die ( "Unabale to connect to the database" );  

008  //select database  

009  mysql_select_db($database_logon) or die ( "Unable to select database!" );  

010    

011 
//specify how many results to display per page  

012 $limit 10;  

013    

014 
// Get the search variable from URL  

015   $var = @$_GET['q'] ;  

016   $s $_GET['s'] ;  

017 //trim whitespace from the stored variable  

018   $trimmed trim($var);   

019 //separate key-phrases into keywords  

020   $trimmed_array explode(" ",$trimmed);  

021    

022 
// check for an empty string and display a message.  

023 if ($trimmed == "") {  

024   $resultmsg =  "<P>Search Error</P><P>Please enter a search...</P>" ;  

025   }  

026    

027 
// check for a search parameter  

028 if (!isset($var)){  

029   $resultmsg =  "<P>Search Error</P><P>We don't seem to have a search parameter! </P>" ;  

030   }  

031 // Build SQL Query for each keyword entered  

032 foreach ($trimmed_array as $trimm){  

033       // EDIT HERE and specify your table and field names for the SQL query  

034      $query "SELECT * FROM tablename WHERE field1 LIKE '%$trimm%' OR field2 like '%$trimm%' OR field3 like '%$trimm%' ORDER BY field1  DESC" ;   

035      // Execute the query to  get number of rows that contain search kewords  

036      $numresults=mysql_query ($query);  

037      $row_num_links_main =mysql_num_rows ($numresults);  

038    

039      
// next determine if 's' has been passed to script, if not use 0.  

040      // 's' is a variable that gets set as we navigate the search result pages.  

041      if (empty($s)) {  

042          $s=0;  

043      }  

044    

045       
// now let's get results.  

046       $query .= " LIMIT $s,$limit;  

047       $numresults mysql_query ($query) or die ( "Couldn't execute query" );  

048       $rowmysql_fetch_array ($numresults);  

049    

050       
//store record id of every item that contains the keyword in the array we need to do this to avoid display of duplicate search result.  

051       do{  

052           $adid_array[] = $row'fieldid' ];  

053       }while( $rowmysql_fetch_array($numresults));  

054  //end foreach  

055    

056 
if($row_num_links_main == && $row_set_num == 0){  

057    $resultmsg "<P>Search results for: "$trimmed."</P><P>Sorry, your search returned zero results</P>" ;  

058 }  

059    //delete duplicate record id's from the array. To do this we will use array_unique function  

060    $tmparr array_unique($adid_array);  

061    $i=0;  

062    foreach ($tmparr as $v) {  

063        $newarr[$i] = $v;   

064        $i++;  

065    }  

066    

067 
// now you can display the results returned. But first we will display the search form on the top of the page  

068 ? >  

069    

070 
<FORM method=get name=search action=search.php>  

071   <DIV>  

072       <INPUT value=" < ?php echo $q; ? > " type=text name=q>  

073       <INPUT value=Search type=submit name=search>  

074   </DIV>  

075 </FORM>  

076    

077 
< ?php  

078 
// display what the person searched for.  

079  if( isset ($resultmsg)){  

080   echo $resultmsg;  

081   exit();  

082  }else{  

083   echo "Search results for: " $var;  

084  }  

085     

086 
foreach($newarr as $value){  

087  // EDIT HERE and specify your table and field names for the SQL query  

088 $query_value "SELECT * FROM tablename WHERE fieldid = '$value'";  

089  $num_value=mysql_query ($query_value);  

090  $row_linkcatmysql_fetch_array ($num_value);  

091  $row_num_linksmysql_num_rows ($num_value);  

092    

093 
//now let's make the keywods bold. To do that we will use preg_replace function.  

094 //Replace field  

095   $titlehigh preg_replace "'($var)'si" "<STRONG> \1</STRONG>" $row_linkcat'field1' ] );  

096   $linkhigh preg_replace "'($var)'si" "<STRONG> \1</STRONG>" $row_linkcat'field2' ] );  

097   $linkdesc preg_replace "'($var)'si" "<STRONG> \1</STRONG>" $row_linkcat'field3' ] );  

098    

099 
foreach($trimmed_array as $trimm){  

100     if($trimm != 'b' ){  

101         $titlehigh preg_replace"'($trimm)'si" ,  "<STRONG> \1</STRONG>" $titlehigh);  

102         $linkhigh preg_replace"'($trimm)'si" "<STRONG> \1</STRONG>" $linkhigh);  

103         $linkdesc preg_replace"'($trimm)'si" ,  "<STRONG> \1</STRONG>" $linkdesc);   

104      }  

105 //end highlight  

106    

107 
? >  

108  <P>  

109 < ?php echo $titlehigh; ? >  

110    

111 
< ?php echo $linkhigh; ? >  

112    

113 
< ?php echo $linkdesc; ? >  

114 </P>  

115     

116 
< ?php  

117 
}   //end foreach $trimmed_array   

118    if($row_num_links_main $limit){  

119    // next we need to do the links to other search result pages  

120       if ($s>=1) { // do not display previous link if 's' is '0'  

121         $prevs=($s-$limit);  

122          echo "<DIV>< a href="$PHP_SELF?s=$prevs&q=$var&catid=$catid" >Previous " .$limit"< /a >  

123 </DIV>"
;  

124       }  

125      // check to see if last page  

126      $slimit =$s+$limit;  

127        if (!($slimit >= $row_num_links_main) && $row_num_links_main!=1) {  

128      // not last page so display next link  

129           $n=$s+$limit;  

130            echo "<DIV>< a href="$PHP_SELF?s=$n&q=$var&catid=$catid">Next " .$limit"< /a >  

131 </DIV>"
;  

132         }  

133     }  

134 }  //end foreach $newarr  

135 ? > 
Aiahoos is offline  
Reply With Quote
Old 02-25-2010, 11:29 PM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Just a word to the wise (not trying to pick on you, sorry!),

php Code:
// This is bad coding practice. Don't use error supression when there are other choices.
$var = @$_GET['q'];

// This is how you should do it;

if ( isset( $_GET['q'] ) ) {
  $var = $_GET['q'];
}

// Or if you prefer ternary's and need a default value for $var
$var = ( isset( $_GET['q'] ) ? $_GET['q'] : '' );
delayedinsanity is offline  
Reply With Quote
Old 02-26-2010, 01:13 AM   #6 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
Just a word to the wise (not trying to pick on you, sorry!),

php Code:
// This is bad coding practice. Don't use error supression when there are other choices.
$var = @$_GET['q'];

// This is how you should do it;

if ( isset( $_GET['q'] ) ) {
  $var = $_GET['q'];
}

// Or if you prefer ternary's and need a default value for $var
$var = ( isset( $_GET['q'] ) ? $_GET['q'] : '' );
I agree, also everytime you use '@' a kitten dies
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 02-26-2010, 09:06 AM   #7 (permalink)
The Acquainted
 
Hightower's Avatar
 
Join Date: May 2009
Location: Durham, UK
Posts: 134
Thanks: 9
Hightower is on a distinguished road
Default

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@

I HATE cats - now the world is a better place!
__________________
Hightower's Softpolio
Send a message via MSN to Hightower
Hightower is offline  
Reply With Quote
Old 10-22-2012, 09:00 AM   #8 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default Coach Outlet

You’ve relativelyCoach Outlet recently arrived in New Delhi after living in two of Asia’s other great cities,Coach Outlet Store Online Tokyo and Hong Kong, for several years. Do these cities feel like they’re part of the same continent? Yes, and no. In terms Coach Factory Onlineof infrastructure, they couldn’t be more different. Getting regularCoach Outlet power and water at my house in New Delhi is never a sure thing, even though Coach Purse Outlet OnlineI’m paying the same rent that I paid in Tokyo and almost the same electricity prices. Both Hong Kong and Tokyo are also crowded places,Coach Factory Outlet Online but both cities are incredibly well planned and efficiently run. Efficient is not a word I would use to describe my Coach Bags Outlet Onlineday-to-day life in New Delhi. On the other hand, one thing that I think Hong Kong and New Delhi have in common isCoach Handbags Outlet a shared sense of optimism — a feeling that the best is yet to come. That’s definitely not the feeling you get in Tokyo,Coach Outlet Online or in the U.S. when I go home. It’s a big part of what I find addictive about living and working in this part of the world. You feel like you’re watching the future unfold.
dashixiong is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem executing MSSQL query in PHP trmbne2000 MySQL & Databases 2 06-30-2009 02:52 PM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
single quotes or double quotes in php planepixel Absolute Beginners 5 02-04-2009 05:48 AM
Problem with Prototype and PHP wiifanatic Javascript, AJAX, E4X 3 02-18-2008 01:39 AM
Differences Between Single and Double Quotes Wildhoney General 19 11-10-2007 11:37 PM


All times are GMT. The time now is 06:17 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design