Tagged Questions
1756
votes
25answers
247k views
How can I prevent SQL injection in PHP?
If user input is inserted into an SQL query directly, the application becomes vulnerable to SQL injection, like in the following example:
$unsafe_variable = $_POST['user_input'];
...
176
votes
8answers
123k views
How to 'insert if not exists' in MySQL?
I started by googling, and found this article which talks about mutex tables.
I have a table with ~14 million records. If I want to add more data in the same format, is there a way to ensure the ...
28
votes
9answers
29k views
A script to change all tables and fields to the utf-8-bin collation in MYSQL
Is there a SQL or PHP script that I can run that will change the default collation in all tables and fields in a database?
I can write one myself, but I think that this should be something that ...
5
votes
2answers
46k views
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO
I've looked through all the other stackoverflow (and google) posts with the same problem, but none seemed to address my problem.
I am using pdo and php.
My code:
$vals = array(
':f'=>$email,
...
4
votes
4answers
2k views
Multi Threaded Comments PHP?
I have a script I wrote I while back for comments, but it is only single threaded. I would like it to be multi-threaded, but only as so a user can reply to a comment, not so a user can reply to a ...
4
votes
3answers
2k views
sql - Mysql : Left join on multiple rows and retrieve 1 row
I have 2 tables:
Table : Movies
MovieID -- Name
1 -- Movie1
2 -- Movie2
Table: Types
MovieID -- Type
1 -- DVD
1 -- Bluray
1 -- VCD
2 -- DVD
...
3
votes
4answers
8k views
How do you insert multiple records into a table at the same time?
I have two tables Accommodation and Facility, which are connected in a many-to-many relationship with a third table, Accommodation_facility.
Accommodation (accommodation_id, accommodation_type, ...
3
votes
1answer
36 views
Find subsidiary by latitude and longitude (geolocation)
I'm looking for a fast MySQL query that returns the nearest location from a simple table:
Table: locations:
id | city | latitude | longitude
...
2
votes
3answers
103 views
Ajax doesn't work on all my forms
I'm using ajax to validate my forms but my form is in a while loop in php and my request ajax work only on my first forms.
My code :
Ajax:
<script type="text/javascript">
...
1
vote
4answers
89 views
WHERE vs HAVING in generated queries
I know that this title is overused, but it seems that my kind of question is not answered yet.
So, the problem is like this:
I have a table structure made of four tables (tables, rows, cols, values) ...
1
vote
1answer
26 views
MYSQL & PHP Display data from multiple tables
Hi I have a database that has three tables with the same fields. I'm trying to get it to display the content, but I'm running into two issues. Here is what is on the PHP file. Can someone please help? ...
1
vote
1answer
42 views
If IDs from two different tables are equal, display name from another table
I'm writing a code for my little admin panel, and since I'm not that advanced of a coder, I'm experiencing some troubles with getting a name using two different tables.
Here's my code so far:
...
0
votes
2answers
2k views
SQL query escaping + codeigniter
I'm using codeigniter and most of the time use active record for my queries (which automatically escapes them), but this query doesn't seem to fit neatly into it because of the variable. So I need to ...
0
votes
3answers
45 views
SQL - Count how many itmes in a GROUP also using SUM
I'm using PDO (still learning) and have the current SQL query. This works perfectly, merging duplicate entries and adding their value. Is there a way I could see how many duplicate entries there were?
...
0
votes
1answer
44 views
PHP - MYSQL Query multiple values from an array
I want to run an insert query in a loop until all the elements from an array pass.
Ex:
$signs = array("aries", "taurus", "gemini", "cancer", "leo", "virgo", "libra", "scorpio", "sagittarius", ...