All Questions

2783
votes
28answers
1307198 views

How can I prevent SQL injection in PHP?

If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example: $unsafe_variable = $_POST['user_input']; m...
2027
votes
13answers
165758 views

Why shouldn't I use mysql_* functions in PHP?

What are the technical reasons for why one shouldn't use mysql_* functions? (e.g. mysql_query(), mysql_connect() or mysql_real_escape_string())? Why should I use something else even if they work on m...
839
votes
23answers
1235717 views

PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"

I am running a PHP script, and keep getting errors like: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php on line 10 Notice: Undefined index: my_index C:\wamp\www\...
417
votes
12answers
345279 views

PHP Parse/Syntax Errors; and How to solve them?

Everyone runs into syntax errors. Even experienced programmers make typos. For newcomers it's just part of the learning process. However, it's often easy to interpret error messages such as: PH...
811
votes
33answers
664574 views

mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource

I am trying to select data from a MySQL table, but I get one of the following error messages: mysql_fetch_array() expects parameter 1 to be resource, boolean given or mysqli_fetch_array() ex...
839
votes
11answers
952435 views

How to fix "Headers already sent" error in PHP

When running my script, I am getting several errors like this: Warning: Cannot modify header information - headers already sent by (output started at /some/file.php:12) in /some/file.php on line 2...
838
votes
30answers
143614 views

Reference - What does this error mean in PHP?

What is this? This is a number of answers about warnings, errors and notices you might encounter while programming PHP and have no clue how to fix. This is also a Community Wiki, so everyone is invit...
333
votes
24answers
206522 views

PHP mail function doesn't complete sending of e-mail

<?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: yoursite.com'; $to = 'contact@yoursite.com'; $subject = 'Customer Inqu...
905
votes
14answers
111807 views

UTF-8 all the way through

I'm setting up a new server, and want to support UTF-8 fully in my web application. I have tried in the past on existing servers and always seem to end up having to fall back to ISO-8859-1. Where ex...
1784
votes
28answers
341443 views

How do you parse and process HTML/XML in PHP?

How can one parse HTML/XML and extract information from it?

Previous Next