Re: Help INSERTing to MySQL

From: Date: Sat, 24 Feb 2001 01:31:30 +0000
Subject: Re: Help INSERTing to MySQL
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41392@lists.php.net to get a copy of this message
> 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>"; > } > } > ?>

« previous php.general (#41392) next »