Re: UPDATE table Problem
| From: | Thomas \"omega\" Henning | Date: | Wed, 17 Oct 2001 17:13:21 +0000 |
| Subject: | Re: UPDATE table Problem | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-13430@lists.php.net to get a copy of this message | ||
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" <glioumis@adacom.com> wrote in message
news:003f01c156d7$f218e640$05041fac@adacom.com...
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!!