Re: Please help a newbie

From: Date: Mon, 20 Apr 2009 00:21:32 +0000
Subject: Re: Please help a newbie
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-46126@lists.php.net to get a copy of this message
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. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.db (#46126) next »