Re: HELP PLEASE!! Get query error when inserting into MySql
| From: | DL Neil | Date: | Sat, 27 Oct 2001 12:54:26 +0000 |
| Subject: | Re: HELP PLEASE!! Get query error when inserting into MySql | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-13768@lists.php.net to get a copy of this message | ||
> I have a query whenever I try to insert something into a mysql table. This is
> the code I am using:
> <?
>
> $host1 = gethostbyaddr("$REMOTE_ADDR");
> $date = date("Y-m-d h:i:s");
> $link = mysql_connect("$host", "$user", "$passwd");
> mysql_select_db("$database", $link);
> $sql = "INSERT INTO vcstats VALUES('', $SCRIPT_NAME, $date, $HTTP_USER_AGENT,
> $BName, $BVersion, $BPlatform, $REMOTE_ADDR, $host1)";
> $result = mysql_query($sql) or die("query error<Br>" . mysql_error());
> mysql_close();
>
> ?>
Robby,
Queries are the term used to describe all interactions with a db - that's why the function is
called
mysql_query.
It would be helpful if you told us the error message you are receiving.
As a matter of style, it would also help you if you checked the response from each function call, or
at least
echo-ed it so that you could see the returned information. In that case, you would see that
processing doesn't
get as far as the INSERT operation before failing, and would be able to focus on working out a
solution from the
manual/your guiding text.
Assuming you define the PHP variables $host, $user, $passwd, and $database, somewhere earlier in the
script,
then the most likely problem is that they are enclosed within quotation marks inside the
mysql_connect() and
mysql_select_db() calls. Quotation marks are only required if string literals are being specified.
Come back to us if that doesn't do the trick,
=dn