awachtel Posted August 22, 2007 Share Posted August 22, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66230-updating-current-database-row/ Share on other sites More sharing options...
Fadion Posted August 22, 2007 Share Posted August 22, 2007 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/66230-updating-current-database-row/#findComment-331416 Share on other sites More sharing options...
awachtel Posted August 23, 2007 Author Share Posted August 23, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/66230-updating-current-database-row/#findComment-332166 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.