RE: [PHP] Help INSERTing to MySQL

From: Date: Sat, 24 Feb 2001 08:17:04 +0000
Subject: RE: [PHP] Help INSERTing to MySQL
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41435@lists.php.net to get a copy of this message
you dont need to have a list of field names if you insert the exact amount of fields that exist in the table... if you have fields Name and Email, you can do: INSERT INTO mytable VALUES ('myname','my@email.com') without a problem. however, if you have fields Name, Email and Password the previous code will break, since MySQL would complain that you're inserting too few (or too many) pieces of data into the table, and it cant decide which data goes where > -----Original Message----- > From: Joe Stump [mailto:jstump@zebulon.miester.org] > Sent: Friday, February 23, 2001 17:21 > To: Clayton Dukes > Cc: php-general@lists.php.net > Subject: Re: [PHP] Help INSERTing to MySQL > > > Before your VALUES you need to have a list of the fields ie: > > insert into table (id,fname,lname) values > ('$id','$fname','$lname') > > --joe > > On Fri, Feb 23, 2001 at 08:00:30PM -0500, Clayton Dukes wrote: > > 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" > > > > > > > > ---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>"; > > } > > } > > ?> > > > > <h1>Submit a new document to the database</h1> > > <form> > > Email Address: <input type=text name=email><br> > > Category: <select name=category><? print "$CATEGORIES" > > ?></select><br> > > Sub Category: <select name=subcategory><? print > "$SUBCATEGORIES" ?></select><br> > > Date Document was written: <input type=text name=date> > > (xx-xx-xxxx)<br> > > Document Subject: <input type=text name=subject><br> > > Document Title: <input type=text name=title><br> > > Document Author: <input type=text name=author><br> > > Document Language: <input type=text name=language value=English><br> > > Grade Received (Percentage): <input type=text name=grade > size=3> (xx/100)<br> > > Grade Level of Paper: <select name=level><option>High > > School</option><option>College</option><option>Other</option></select><br> > > City in which paper was submitted: <input type=text name=city > value=Jacksonville><br> > > State in which paper was submitted: <input type=text name=state > value=FL><br> > > County in which paper was submitted: <input type=text > name=county value=Duval> <b>(County, not Country!)</b><br> > > School at which paper was submitted: <input type=text > name=school value="Mandarin High School"><br> > > ZIP code: <input type=text name=zip size=5 value=32257> <b>(Put > your ZIP code in if you don't know your school's)</b><br> > > Author's Comments: <input type=text name=authors_comments><br> > > Teacher's Comments: <input type=text name=teachers_comments><br> > > Document (ASCII TEXT ONLY):<br> > > <textarea name=docdata cols=80 rows=30>Paste document text > here</textarea> > > <p><input type=submit value="Submit for verification"> > > </form> > > > > -----END----- > > > > > > > > TIA! > > Clayton > > > > > -- > > 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 > > -- > > ------------------------------------------------------------------------------- > Joe Stump, PHP Hacker, joestump98@yahoo.com -o) > http://www.miester.org http://www.care2.com > /\\ > "It's not enough to succeed. Everyone else must fail" -- Larry Ellison _\_V > ------------------------------------------------------------------------------- > > > -- > 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 >

« previous php.general (#41435) next »