UPDATE table Problem
| From: | George Lioumis | Date: | Wed, 17 Oct 2001 06:50:02 +0000 |
| Subject: | UPDATE table Problem | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-13412@lists.php.net to get a copy of this message | ||
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!!