List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:April 13 2000 11:38pm
Subject:Re: INSERT syntax
View as plain text  
>Sasha,
>
>The error is that the insert does not happen.  There are no error messages.
>The part that is supposed to print to the screen prints to the screen.  But
>nothing goes into the database.

Why aren't you doing error-checking?

There aren't any error messages because you haven't printed any.
In general, you don't want to call mysql_query() without checking
the result.  Try something like this, which will print both the
error message and the query that failed:

	if (!mysql_query ($query_string))
		die ("Yow! An error: "
			. mysql_error ()
			. "\nQuery was: "
			. htmlspecialchars ($query_string));

If you want an error message from a failed query, it's your
responsibility to provide it.

Also, you should addslashes() your variables before you
construct your query string.  If any of them contain a quote
or backslash, you might have problems.

	$lastname = addslashes ($lastname);
	$firstname = addslashes ($firstname);
	$email = addslashes ($email);
	$colors = addslashes ($colors);
	$website = addslashes ($website);

>
>Margie
>
>>  > Thanks Sasha.
>>  >
>>  > Here it is.  There must be something obvious I'm overlooking.
>>  >
>>  > Margie
>>  >
>>  > <HTML>
>>  > <BODY>
>>  >
>>  > <?php
>>  >
>>  > $link = @mysql_pconnect("localhost","myusername","mypassword")
>>  >  or exit();
>>  > mysql_select_db("mydatabase");
>>  >
>>  > $result = stripSlashes($query);
>>  > $result = mysql_query($query,$link);
>>  >
>>  > include("C:/php3/includes/common.inc");
>>  >
>>  > / / -------Print to the screen the info the user has entered-------
>>  > / / This part doesn't give me any problems
>>  >
>>  >  echo stripslashes("<B>Last Name:</B> $lastname" .....
>>  >     .....
>>  >     .....
>>  >
>>  > / /-------member table-------
>>  > / / Here's the part that gives me trouble
>>  >
>>  > $colors = addslashes(implode(", ", $colors));
>>  >
>>  >     mysql_query("INSERT INTO
>member(lastname,firstname,email,colors,website)
>  > >     VALUES('$lastname','$firstname','$email','$colors','$website')");
>  > >
>>  > / / ----------master table-------
>>  > / / ---------I have to do write this part, yet
>>  > / / Look up the member_id and color_id
>>  > / / Use them to create a new master table entry
>>  >
>>  > mysql_free_result($result);
>>  >
>>  > ?>
>>  > <HR><BR>
>>  > <FORM ACTION=processform.php3 METHOD=POST>
>>  >    <INPUT TYPE=SUBMIT VALUE="New query">
>>  > </FORM>
>>  >
>>  > </BODY>
>>  > </HTML>
>>  >
>>  > >
>>  > > It is not necessary to pass the MYSQL connection link to PHP mysql
> API
>>  > calls
>>  > > unless you have more than one currently open. However, it is
> necessary
>to
>>  > check
>>  > > for errors and take action in case they happen.
>>  > >
>>  > > Post your full code, as well as the output it produces, and we can
>take a
>>  > look
>>  > > at it...
>>  > >
>>  > > --
>>  > > Sasha Pachev
>>  > >
>>  > > +------------------------------------------------------------------+
>>  > > | TcX  ____  __     _____   _____  ___     ==  mysql@stripped        |
>>  > > |     /*/\*\/\*\   /*/ \*\ /*/ \*\ |*|     Sasha Pachev            |
>>  > > |    /*/ /*/ /*/   \*\_   |*|   |*||*|     mailto:sasha@stripped  |
>>  > > |   /*/ /*/ /*/\*\/*/  \*\|*|   |*||*|     Provo, Utah, USA        |
>>  > > |  /*/     /*/  /*/\*\_/*/ \*\_/*/ |*|____                         |
>>  > > |  ^^^^^^^^^^^^/*/^^^^^^^^^^^\*\^^^^^^^^^^^                        |
>>  > > |             /*/             \*\ Developers Team                  |
>>  > > +------------------------------------------------------------------+
>>  > >
>>
>>  And what is the error?
>>  --
>>  Sasha Pachev
>>
>>  +------------------------------------------------------------------+
>>  | TcX  ____  __     _____   _____  ___     ==  mysql@stripped        |
>>  |     /*/\*\/\*\   /*/ \*\ /*/ \*\ |*|     Sasha Pachev            |
>>  |    /*/ /*/ /*/   \*\_   |*|   |*||*|     mailto:sasha@stripped  |
>>  |   /*/ /*/ /*/\*\/*/  \*\|*|   |*||*|     Provo, Utah, USA        |
>>  |  /*/     /*/  /*/\*\_/*/ \*\_/*/ |*|____                         |
>>  |  ^^^^^^^^^^^^/*/^^^^^^^^^^^\*\^^^^^^^^^^^                        |
>  > |             /*/             \*\ Developers Team                  |
>>  +------------------------------------------------------------------+
>>
>
>
>--
>---------------------------------------------------------------------
>Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
>posting. To request this thread, e-mail mysql-thread34165@stripped
>
>To unsubscribe, send a message to:
>     <mysql-unsubscribe-paul=snake.net@stripped>


-- 
Paul DuBois, paul@stripped
Thread
INSERT syntaxMargie Wiers13 Apr
  • Re: INSERT syntaxThimble Smith13 Apr
  • Re: INSERT syntaxMargie Wiers14 Apr
  • Re: INSERT syntaxMargie Wiers14 Apr
  • Re: INSERT syntaxNiall Kavanagh14 Apr
  • Re: INSERT syntaxMargie Wiers14 Apr
  • Re: INSERT syntaxNiall Kavanagh14 Apr
  • Re: INSERT syntaxsasha14 Apr
  • Re: INSERT syntaxMargie Wiers14 Apr
  • Re: INSERT syntaxMargie Wiers14 Apr
    • Re: INSERT syntaxPaul DuBois14 Apr
  • Re: INSERT syntaxMargie Wiers14 Apr
  • Re: INSERT syntaxMargie Wiers14 Apr
    • Re: INSERT syntaxPaul DuBois14 Apr
  • Re: INSERT syntaxsasha14 Apr
  • Re: INSERT syntaxMargie Wiers14 Apr
  • Re: INSERT syntaxMargie Wiers14 Apr
RE: INSERT syntaxQuentin Bennett14 Apr
Re: INSERT syntaxMargie Wiers14 Apr
  • Re: INSERT syntaxPaul DuBois14 Apr