Re: [PHP-DB] Please help a newbie

[email protected] (mrfroasty)
Newsgroups php.db
Message-ID <[email protected]>
Thanks....
Great tip there...

Gr
mrfroasty


Chris wrote:
> mrfroasty wrote:
>> Hello,
>>
>> May be try something like this:
>>
>> $query1=
>> CREATE TABLE contacts(
>> id int(16) NOT NULL auto_increment,
>> phone varchar(15)  NOT NULL,
>> name varchar(15) NOT NULL,
>> address varchar(15) NOT NULL,
>> PRIMARY KEY (id)
>> );
>>
>> $query2 = "INSERT INTO contacts VALUES ('NULL','$phone', '$name', 
>> '$address')";
>>
>> P:S
>> id incremented automatically by MYSQL now
>
> Maybe - but it's by accident. You're trying to insert the word NULL 
> into an int field (it's being treated as a word because of the single 
> quotes around it).
>
> Don't specify the id field at all:
>
> $query2 = "insert into contacts(phone, name, address) values ('" . 
> mysql_real_escape_string($_POST['phone']) . "', '" . 
> mysql_real_escape_string($_POST['name']) . "', '" . 
> mysql_real_escape_string($_POST['address']) . "')";
>
> You should always use the field names (as above) because if your table 
> gets reordered, your inserts will now break - if you put "name" before 
> phone, the data is now going into the wrong fields.
>


-- 
Extra details:
OSS:Gentoo Linux-2.6.25-r8
profile:x86
Hardware:msi geforce 8600GT asus p5k-se
location:/home/muhsin
language(s):C/C++,VB,VHDL,bash,PHP,SQL,HTML,CSS
Typo:40WPM
url:http://mambo-tech.net
url:http://blog.mambo-tech.net
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.