On Tue, 2004-04-06 at 20:09, Chris W. Parker wrote:
> Chris W. Parker <>
>     on Tuesday, April 06, 2004 5:01 PM said:
> 
> let me expand both of my points in an attempt to be more verbose.
> 
> > 1. write readable queries.
> > 2. always put single quotes around array keys. $array['key']
> 
> here is how i would write your query:
> 
> <?php
> 
>   $sql = "
>         insert into $EventsTable
>             values(
>                 NULL
>                 , '{$_SESSION['add']['type]}'
>                 , '{$_SESSION['add']['start_date']}'
>                 , '{$_SESSION['add']['end_date']}'
>                 , '{$_SESSION['add']['name']}'
>                 , '{$_SESSION['add']['county']}'
>                 , '{$_SESSION['add']['discription']}'
>                 , '{$_SESSION['add']['StartingDay']}'
>                 , '{$_SESSION['add']['StartingMonth']}'
>                 , '{$_SESSION['add']['StartingYear']}'
>                 , '{$_SESSION['add']['EndingDay']}'
>                 , '{$_SESSION['add']['EndingMonth']}'
>                 , '{$_SESSION['add']['EndingYear']}'";
> 
> 
>   $sql = "
>         insert into $GuestbookTable
>             values(
>                 NULL
>                 , '{$_SESSION['add']['date']}'
>                 , '{$_SESSION['add']['name']}'
>                 , '{$_SESSION['add']['email']}'
>                 , '{$_SESSION['add']['website']}'
>                 , '{$_SESSION['add']['referred']}'
>                 , '{$_SESSION['add']['comments']}')";

I don't advise this type of insert query. If you ever add a new field to
the table all of your queries will break since this style requires
ordered matching of values to table fields for every field in the table.
You should use the field names in the query:

$sql = "
    INSERT INTO $guestbookTable
    (
        field1,
        field2,
        field3
    )
    VALUES
    (
        '$value1',
        '$value2',
        '$value3'
    ) ";

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to