Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am doing my project and I am using php and MySQL
My program is reading a data from textarea as a list of people, I use the explode function to separate the list and then I generate a for loop to insert them to MySQL database
till this part I don't have any problems
The problem is when I query the database with a where condition specifying a name from the list it does not recognize it
My question does the explode function change any thing to the names in the list or add any special characters
because I use the same functionality with specific name and it goes smoothly
Thanks in advance
It should not. PHP explode will not change your text and the WHERE query should operate correctly.
Are the characters all utf8 encoded? Check the database and see what you are querying for actually exists the same way you are sending it.
Like the others said, if you can provide us an example of the following it would be great:
Actual textarea input (not exploded).
DB Dump of what is inserted.
Your QUERY to select
Additionally, it could be a space issues, use trim before you insert the data or in your query instead of field = '$a' do a field LIKE '%$a%'
I don't think explode() will modify anything. try to use trim() in your foreach loop before inserting. Might be some characters that can not be seen.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am writing a small program where I want to extract user input strings from MySQL database. But I am not looking for exact matching strings. For example
If user types amazon then it should extract amazon from the database. But if user types amazonn or amazo or amozon it should still retrive amazon because it is the nearest word to the misspelled word.
This is something similar to google suggestions while searching. Is there anyway to define a function like this in PHP? Do i have to import dictionary and compare with it?
You could use strpos() in two ways
How do I check if a string contains a specific word in PHP?
Search for the DB string in the string that the user inputted.
And the other way around:
Search for the string that the user inputted in the DB string.
The problem with this is that you only cover differences at the outside of the string
such as amazo or amazonn but not amozon
Or you could use levenshtein() and similar_text() as stated in the comments.
Good example code with suggestions:
https://codereview.stackexchange.com/questions/27173/php-spell-checker-with-suggestions-for-misspelled-words
That should be covered in an entirely different way...
I think you want both checks but everything is going to be difficult without a dicitonary so I suggest importing one ;)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Lets say we have a very big (a lot of rows and cells) table in our database and we are looking for a very special value.
Which way will show us the result earlier?
a) put the table in a php array and get through this array
b) search for the value with sql commands
The database with an index on the column should be faster.
Even without an index, as you describe the problem, the database would be faster. Just moving the data to the php array is an expensive operation. Even if the database has to do a full table scan, it will only be moving back the row that you care about.
Assuming that the columns you are searching on are properly indexed, using SQL directly should be substantially faster. Otherwise, you have to select the entire table and loop through it in PHP without the benefits of indexes.
If you cannot search on an index for whatever reason, I think that both methods would be very slow. Essentially, there is no benefit to searching with PHP alone.
If the table is big, fetching the data to fill the array will take time, and searching in an big array will be slow (unless you have a special indexing method for your array), whatever language you use , php, java, c# or other.
Put an index on the column you are searching for: row, cell or only value (if you search only for a value), it depends on your search.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am simply inserting the text that you write in the textarea in mySQL without using any extra method to protect my site... Actually i just made a test wrote the html code that creates a input textbox to the textarea and saved it into mysql, which prints me the component on the page...
How can i make it write secure content on textarea that does not allow you to write html tags or smth, I just wanna increase the security of my site.
Thanks
if $textarea contains your textarea value,you can do $db_value = mysql_real_escape_string(strip_tags(trim($textarea))) and insert $db_value to the database.
strip_tags strips the text of html tags and mysql_real_escape_string encodes special characters and makes it safe to insert into a database...
for mysql_real_escape_string: check http://php.net/manual/en/function.mysql-real-escape-string.php
for strip_tags check: http://www.php.net/manual/en/function.strip-tags.php
Try to use Prepared Statements
http://php.net/manual/de/mysqli.quickstart.prepared-statements.php
And remove all unwanted chars from the given text and finally use mysql_real_escape_string
to escape the string for MySQL.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am a new user of php.
I have one table in mysql database. I have a form which the users use to query the mysql database. I am testing my html form page on my linux laptop which has APACHE server.
I am able to make a connection to the mysql database and display results in the browser.
I am not sure how to capture the results from the variable which has query results which has several rows of data and be able to write the results to a text file in /var/www/
Thank you
I noticed every time you check if the POST variable is set you use something like
if(isset($POST["submit"])){
Was that a typo in this post or are you forgetting the underscore?
if(isset($_POST["submit"])){
Also try to use mysql_fetch_assoc instead of mysql_fetch_array.
And always prepare the variabes for usage in a query if you do not want to get hacked instantly.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a PHP script that displays data read from a MySQL database. I want to filter the output to only show rows where two columns contain specific values. How do I do this?
Add a WHERE clause, e.g., WHERE column1 = 'specific-value1' AND column2 = 'specific-value2'
Here's a link to MySQL's SELECT syntax:
http://dev.mysql.com/doc/refman/5.1/en/select.html
(and in German):
http://dev.mysql.com/doc/refman/5.1/de/select.html
no idea why you are posting in german on an english site and then translating it to english. But what you need to do is something like "select * from table where column1='val' and column2='val'". Though it sounds like you have a large set of data pulled off already and you want to filter that. I don't see why you shouldn't just query what you need from the database instead of pulling everything off and then filtering.