Re: Help INSERTing to MySQL

From: Date: Sat, 24 Feb 2001 01:55:01 +0000
Subject: Re: Help INSERTing to MySQL
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-41423@lists.php.net to get a copy of this message
Thanks! :-) Man, what a great list! You guys kick a$$ ----- Original Message ----- From: "Kyndig" <kyndig@clds.net> To: "Clayton Dukes" <cdukes@cdukes.com>; "Philip Olson" <philip@cornado.com> Cc: <php-general@lists.php.net> Sent: Friday, February 23, 2001 8:50 PM Subject: Re: [PHP] Help INSERTing to MySQL > On Fri, 23 Feb 2001, Clayton Dukes wrote: > > Well sheesh, > > If I knew I could get answers that easy here, I woudn't have worked on this > > for 20 hours :-) > > > > THANKS!!!! > > > > btw, field one is an ID field set to auto increment, how can I insert that > > if I don't know what it is? > > > You don't need to insert it. auto_increment will automatically > increment every time you insert a record. In fact, you _really_ > don't want to ever set this field, as you would be modifying your > primary key ( unless your modifying them all ) > > Note: You don't have to INSERT all fields mentioned below. If > you have a 'default' value set..then it will default to that value, > or in auto_increment case...it will automatically increment from > the last record it reads. > > > > > Here are the fields: > > CREATE TABLE documents ( > > id bigint(20) DEFAULT '0' NOT NULL auto_increment, > > docid varchar(20), > > category enum('Language > > Arts','Sciences','Humanities','Arts','Special > > Subjects','Other'), > > subcategory > > enum('Physics','Biology','Chemistry','Math','Computers > > and > > Internet','History','Economics','Geography','Law','Religion','Philosophy','B > > lack > > Awareness','Countries','Drugs','Education','Environmental > > Awareness','Politics','Health','Sex and > > Sexuality','Female > > Awareness','Art','Movies or > > TV','Music','Sports','Charles > > Dickens','Shakespeare','Biography','Fictional > > Stories','Astronomy','Mythology'), > > date varchar(10), > > subject varchar(200), > > title varchar(200), > > author varchar(200), > > email varchar(50), > > language enum('English','Danish','Dutch','Finnish','German','Spanish'), > > grade int(3), > > level enum('High School','College','Other'), > > city varchar(15), > > state varchar(15), > > county varchar(15), > > school varchar(45), > > zip smallint(5), > > authorcomments varchar(200), > > teachercomments varchar(200), > > approve enum('Y','N'), > > docdata text, > > PRIMARY KEY (id), > > UNIQUE id (id) > > > > > > ----- Original Message ----- > > From: "Philip Olson" <philip@cornado.com> > > To: "Clayton Dukes" <cdukes@cdukes.com> > > Cc: <php-general@lists.php.net> > > Sent: Friday, February 23, 2001 8:31 PM > > Subject: Re: [PHP] Help INSERTing to MySQL > > > > > > > > > > > Hello, This is my first attempt, so I'm prolly doing something stupid, > > > > but can someone tell me why this doesn't work? All it returns is > > > > "Unable to INSERT to database" > > > > > > Change : or die("Unable to INSERT to database"); > > > To : or die(mysql_error()); > > > > > > And see what it tells you. Odds are there's a field not being accounted > > > for. When not designating columns (just values) it's important to make > > > sure all columns are accounted for. See : > > > > > > http://www.sqlcourse.com/ > > > > > > It'll provide some basic SQL help. It's recommended to write out columns > > > and values (easier to make sense of). > > > > > > > > > Regards, > > > > > > Philip Olson > > > http://www.cornado.com/ > > > > > > > > > > > > > > > ---BEGIN--- > > > > <? > > > > $time = time(); > > > > $rand = Random_Password(5); > > > > $docid = $time . $rand; > > > > > > > > if (isset($email) && isset($docid)) { > > > > mysql_connect("$HOSTNAME", "$DB_USER", > > > > "$DB_PASS"); > > > > > > > > $query = "INSERT INTO documents VALUES ('$docid', > > > > '$category', > > > > '$subcategory', '$date', '$subject', > > > > '$title', '$author', '$email', > > > > '$language', '$gr ade', '$level', > > > > '$city', '$state', '$county', > > > > '$zip', '$authors_comments', '$teachers_comments', > > > > 'N', '$docdata')"; > > > > > > > > $result = mysql_db_query("$DATABASE", $query) or die("Unable > > > > to > > > > INSERT to database"); > > > > > > > > if ($result) { > > > > echo "<p>$docid was added to the database</p>"; > > > > } > > > > } > > > > ?> > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > -- > Kind Regards, > --- > Kyndig > Online Text Game Resource Site: http://www.kyndig.com > ICQ# 10451240

« previous php.general (#41423) next »