List:General Discussion« Previous MessageNext Message »
From:Van Date:May 10 1999 5:44pm
Subject:Re: PHP and mysql_result Need to reference the record I just ins
View as plain text  
Don Read wrote:
> 
> On 08-May-99 Van wrote:
> > Okay, I'm beatin' myself up, and 4900 archived mysql messages later,
> > still dying on the vine.
> > Doing a feedback form in PHP.  Works fine.  Inserts the record.  Code
> > follows:
> > $link = mysql_connect($dbhost, $dbuser, $dbpasswd);
> > mysql_select_db($db,$link);
> >
> > $Result=mysql_query("INSERT INTO $dbtable VALUES ('', '$UserAgent',
> > '$Referer',
> >       '$ScriptFilename', '$HitTime', '$RemoteHost', '$RemoteAddr',
> >       '$EmployeeRating', '$SafeComments','$FullName','$eMail')", $link);
> >
> > $CommentId=$Result[1];
> > echo "<center>CommentId=$CommentId; Result=$Result";
> > mysql_close($Result);
> >
> 
> That works ??
> as a C pgmr -> php newbie i get real shy about quoting in php; i always sprintf
> the query, but if you say so ...
> 
> anyhow try:
>   if (mysql_query(INSERT INTO .... )) {
> 
>     $CommentId=mysql_insert_id($link);
>     printf("<center>CommentId=%d Result=%d\n",$CommentId, $Result);
>   } else
>      echo "really bad vibes, dude ..";
> 
Appreciate the alternative approach, Don.  Yes, I use this method to
connect and query and have for over a year in PHP, and, works fine.  You
can confuse yourself, however, from time to time \"shelling\" in out of
static html to php code, using echos, if you\'re not carefull.  I also,
do some C, and like your approach.  More streamlined.  In my case,
however, simply $CommentId=mysql_insert_id() (given there's an
autonumber field in the table), works fine.
Van
-- 
=========================================================================
Linux rocks!!!   www.dedserius.com
=========================================================================
Thread
How enable symlink-aware behavior?Scott Weikart3 Apr
  • How enable symlink-aware behavior?Michael Widenius3 Apr
  • PHP and mysql_result Need to reference the record I just insertedVan9 May
    • RE: PHP and mysql_result Need to reference the record I just insDon Read10 May
      • Re: PHP and mysql_result Need to reference the record I just insVan10 May