View Full Version : help to understand this code

11-23-2006, 05:48 PM
$query = "INSERT INTO `person` VALUES ('', '$title', '$content', '$submission', '$web', '$person', '$email', '$tele', '$address', '', '$type')";
@$result=mysql_query($query,$link) or die("no connection on insert");

could someone explain about this code. query is use to search. is INSERT INTO 'person' that what has been found is inseted to a new table? values are those fields of some tables? what about this line:
@$result=mysql_query($query,$link) or die("no connection on insert");

11-23-2006, 07:22 PM
everything after 'VALUES' is a value (!) that is being inserted into the person table of a database- the names of the variables seem pretty self explanatory, but listing the column names (in brackets, before VALUES) is generally a good idea.
The first line is assigning the string containing the sql to the variable $query, and the second line is sending it to the database. The @ suppresses error messages (not a good thing on code that you don't understand...) and the 'or die(' bit means that should the query fail, then the error message will be shown (the text given is a little misleading as there are a number of other reasons why it might fail...).

You seem to think this has something to do with searching, which seems unlikely to me based on the fieldnames, but some context to the code (what application it's from? what the filename is called? the function name if it's within one? some code that precedes that you've given?) would all help.