[*NOTE* - I sent this yesterday.  Since I didn't receive a copy
 back from the listprocessor, I assumed that it was lost somewhere
 along the way.                                             --TGN ] 

Hmmmmmmmmmmmmmm.... I'd first put a "or die" clause onto
the clause...

   $updated = mysql_query($update_query);

..like this because I suspect that it's dying before it can
execute ...

   $updated = mysql_query($update_query) or die ("Invalid SQL
[$update_query]");

... what I would currently suspect to find would be the 
'times_visited' column is numeric instead of alphanumeric.
When the update happens, it chokes at having the value your
setting for 'times_visited' quoted with apostrophes....

Originally, it looks like this...

   $update_query = "update guestbook set last_access=now(),
times_visited='$times' where guest_id='$g_id'";

.. if "times_visited" is numeric, I'd change it to ...

   $update_query  = " update guestbook ";
   $update_query .= "    set last_access=now(), ";
   $update_query .= "        times_visited = $times ";
   $update query .= "  where guest_id='$g_id'";

As another note, if the column "last_accessed" is of a "timestamp"
data type, then you can do the following update to cause it to
automagically update with a "now()" value being put into it as well.


   $update_query  = " update guestbook ";
   $update_query .= "    set times_visited = $times ";
   $update query .= "  where guest_id='$g_id'";

This works because "timestamp" column types that aren't mentioned
directly in the update/insert query types are automatically set to
the current system time (which would be a now()).

--
    __           _                                Tyler Nally
   / /__  ____ _(_)___  ____   ____  _________ _  [EMAIL PROTECTED]
  / / _ \/ __ `/ / __ \/ __ \ / __ \/ ___/ __ `/  317-860-3016
 / /  __/ /_/ / / /_/ / / / // /_/ / /  / /_/ /   American Legion Website
/_/\___/\__, /_/\____/_/ /_(_)____/_/   \__, /    http://www.legion.org
       /____/                          /____/   


> -----Original Message-----
> From: Thomas "omega" Henning [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, October 17, 2001 12:13 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Re: UPDATE table Problem
> 
> 
> Dear Sir George Liomis,
> 
> But there is still the update command issue why didn't my 
> update command
> work when i tryed it in my php source it didn;t work but in 
> the mysql shell
> it updated it for me. Is it a bug in php 4.0.5? that it 
> doesn;t send it 2
> the server?
> 
> Sir Thomas "omega" Henning
> "George Lioumis" <[EMAIL PROTECTED]> wrote in message
> news:003f01c156d7$f218e640$[EMAIL PROTECTED]...
> Dear Sirs!!
> 
> I've ended up with a conclusion after MANY hours in front of my PC.
> The problem was not the query but the $guest_id.
> In a first query, I was getting the guest_id from the DB with 
> the following
> statement:
> 
> $get_guest_id_query = "select guest_id from guestbook where
> username='$username' and password='$password'";
> $result = mysql_query($get_guest_id_query) or die (mysql_error());
> The problem was that $result was not in fact what I wanted 
> (ie: guest_id).
> So the following query refused to do its job!
> 
> $update_query = "update guestbook set last_access = now() where
> guest_id='$result'";
> $udated = mysql_query($update_query) or die (mysql_error());
> 
> Below, you can see the correct code:
> 
> if ( ($submit== "Login") and ($username != "") and ($password != "") )
>  {
>  $guest_id = mysql_query("select guest_id from guestbook where
> username='$username' and password='$password'") or die(mysql_error());
>  while ($row = mysql_fetch_array($guest_id))
>  {
>  $g_id = $row["guest_id"];
>  ///set $g_id as global (inter-page!!) variable.
>  session_register('g_id');
>  }
>  mysql_free_result($guest_id);
> if ($g_id >= "1") ///user authenticated...
>  {
>  ///Find user's last access time...
>  $prev_access_query = "select name, mail, times_visited, 
> last_access from
> guestbook where guest_id='$g_id'";
>  $result=mysql_query($prev_access_query);
>  while ($row=mysql_fetch_array($result))   <---------The 
> correct way to get
> geust_id from the $results!!!
>  {
>  echo "<B>Guest: </B>";
>  echo $row["name"];
>  echo " with mail: ";
>  echo $row["mail"];
>  echo "<BR>entered this site in: ";
>  echo $row["last_access"];
>  echo ".<BR>This Guest has visited ";
>  $times = $row["times_visited"] + 1;
>  echo $times;
>  echo " times this site.<BR><BR>";
>  } ///while
>  $update_query = "update guestbook set last_access=now(),
> times_visited='$times' where guest_id='$g_id'";
>  $updated = mysql_query($update_query);
>  if ($updated)
>   {
> ?>
> <FONT SIZE="5"><B><A HREF="main.php">ENTER</A></B></FONT><BR><BR
> <?php
>   } ///if($updated)
>  } ///if($g_id)
>  } ///if ($submit)
> 
> Hope this helps a bit!!

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to