List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:April 14 2000 12:36am
Subject:Re: INSERT syntax
View as plain text  
>Thanks, Paul.
>
>I  forgot to put error checking on this page.  I put in the message you
>wrote and the exact error message is
>
>Yow! An error: Query was empty Query was:


If you put in *exactly* what I wrote, that makes sense, unless you
assigned $query_string to be the query you had literally in your
previous message to the list.  Assign $query_string to be that
query, and try it again.  You'll probably get a different result.

Another value of printing the query (once you've gotten it not to
be empty) is that you'll often see just where the problem is.
Constructing queries in PHP (or Perl) sometimes results in
a query that's just slightly different than what you intend,
and it's often easier to see just what went wrong if you show
the query itself.


>
>Something is not connecting.  I can INSERT, DELETE, etc.  when I am working
>through the mysql client.  But when I attempt to do the same via the Web
>page I've created, the above is what happens.
>
>Thanks,
>Margie
>
>
>>  >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>

-- 
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