Re: Please help a newbie

From: Date: Mon, 20 Apr 2009 00:46:12 +0000
Subject: Re: Please help a newbie
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-46127@lists.php.net to get a copy of this message
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

« previous php.db (#46127) next »