Jump to content

Updating current database row


awachtel

Recommended Posts

I've been developing in classic ASP for 5 years and have decided to try my hand at PHP.  So far I've been very impressed with the simplicity of the syntax and efficiency of the system overall.  The only issue I've had so far is how I can update the current row recieved from a database connection (I'm using IIS and SQL 2005 for now until I migrate my apps).  In ASP, I could do the following:

 

oRS = DBConnection("SELECT * FROM People where PersonLogin='"&request("Login")&"'")

 

To get values from a resultset:

FirstName = oRS("FirstName")

To update that same resultset inline:

oRS("LastUpdated") = now()

oRS.Update

 

Using the above code, I could query the server to validate the login, if successful I could update their row in the DB using the same resultset and only one DB connection.

In my sample PHP app, I have a simple user login, when they log in successfully, I want to update their row in the database and specifically update a column named "MemberLastLogin" with the current date.  Do I have to make two separate DB connections, 1 to test the login and 2 to update their row?  Or can I do this with a single connection.  Thanks.

 

- Adam

Link to comment
Share on other sites

Ive been using VB6 for some database apps for some time and with the recordset controls it was easy as hell to make db connections. I know nothing about asp (not interested though), but from what i can see in your code ure using recordsets. Normally u should make two queries and a simple real world example would look like:

 

$login = mysql_real_escape_string($_POST['login']);
$pass = mysql_real_escape_string($_POST['pass']);
$query = @mysql_query("SELECT * FROM people WHERE personlogin=''") or die(mysql_error());
$values = mysql_fetch_array($query);
if(mysql_num_rows($query) != 0 and $values['password'] == md5($pass)){
     $id = $values['id'];
     $date = date('d/m/Y h:m:s');;
     $queryUpdate = @mysql_query("UPDATE people SET lastlogin='$date' WHERE id='$id'") or die(mysql_error());
} else{
     echo "Your login data are incorrect";
}

Link to comment
Share on other sites

Yea I figured that was the way to go.  The recordset functionality in VB/ASP is definitely one of the most powerful and useful functions of the language, but doing it this way is fine too.  Just wanted to make sure before I coded and entire site this way.  Thanks for the reply!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.