chili5 said:
Ah orjan you are brilliant!
Although I'm sure I set auto_increment. :confused:
What is less than ideal though?
Well, the fact you use just the strings to insert into the query. I'll give you an example of what might go wrong:
Someone uses a ' in their article
$article="don't use this.";
$title="test";
$dates="2009-04-03";
$query = "INSERT INTO articles (date,title,article_text,user) VALUES('$dates','$title','$article','$_SESSION[username]')";
the query now will be:
Quote
INSERT INTO articles (date,title,article_text,user) VALUES('2009-04-03','test','don't use this.','James')
when you try to run this query, it will result in an error because of the ' .
A solution to this is "mysql_real_escape_string". This will add a \ to every special character like this:
'=>\'
"=>\"
=>\n
This way you make sure there cannot be errors by using special characters,and with selects, updates and deletes, you secure your query for sql injection.
sql injection occures like this:
$sql="SELECT * FROM table WHERE name='".$name."'";
now if someone does the folowing:
$name="test' OR ''='"
$sql="SELECT * FROM table WHERE name='".$name."'";
the query will be:
$sql="SELECT * FROM table WHERE name='test' OR ''=''";
wich will result in every row in your table. now this will only show every row in your table, but imagine an UPDATE or a DELETE FROM.
I hope this helps