If you don't put fields name as in: INSERT INTO news VALUES(...., ....)
this means you are going to give values to all the fields in the table (in
their order).
If you specify fields after table name: news(body, date) this means VALUES()
would be adding to these specific fields...

now as for putting NULL, this means that the fields will get the default
value, if it was autoincrement it will be also stored there.

Usualy ID fields are autoincrement and always inserted with NULL values so
that MySql will assign a valid value.

"Peter" <[EMAIL PROTECTED]> wrote in message
> HI,
> I am new to this PHP thing.
> I was working out of my PHP book and website and I noticed some
> discrepancies in inputting data into the MySQL database.
> I followed the example from my book and I noticed that the syntax for
> putting data into a mysql database from PHP was like this:
> $sql = "INSERT INTO news
> VALUES (NULL,'$heading','$body','$date','$auth','$auth_email')";
> However I read some information on the website and I noticed that they
> added the field names right after the name of the table like this:
> mysql_query ("INSERT INTO tablename (first_name, last_name)
>                 VALUES ('$first_name', '$last_name')
>              ");
> I have two questions:
> In the first example what is the meaning of putting the "NULL" before the
> variables?
> I was successful in entering data from my first example without declaring
> field names, so why did they declare in field names in the second example?
> If anyone can shed some light on this question, I would be most grateful.
> Thanks.
> Peter

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to