MesaFloyd Posted April 20, 2008 Share Posted April 20, 2008 I am a layperson, please be gentle. I have a login script that works fairly well. It sets cookies for people that login. I would like to have that persons datetime field get updated whenever he revisits the site if his cookie is still active. I added 4 lines of code that should do it, but does not<heavy sigh>... the result is a blank screen, I remove the lines and all is back and OK. 4 lines of code... simple right???? not for me.... ;-) Here is the code.. I added a few lines before and after so you can see the setup... My problem lines are numbered #1...#4... Thanks in advance function displayLogin() { global $logged_in; if($logged_in) { //FK----attempt to update datetime field for people that log visits to the site // $query = "UPDATE users SET datetime=date("Y.m.d - H:i:s"), //Line#1 // WHERE username='$_SESSION[username]'"; //Line#2 // $result = mysql_query($conn, $query) //Line#3 // or die ("could not execute the query."); //Line#4 //FK-----attempt end echo "<br><h1>Logged In!<br><br></h1>"; echo "Hello <b>$_SESSION[username]</b> you are logged in.<br> You can see the // where I been tesing to control those lines (Maybe you can also tell me how to disply the error message rather than just a blank screen) Any help would be very appreciated.. please be simple in you explanations Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/101929-solved-how-to-update-an-existing-field-php-and-mysql-4-lines-of-code-ugh/ Share on other sites More sharing options...
DeanWhitehouse Posted April 20, 2008 Share Posted April 20, 2008 ok, try this these lines should work <?php mysql_connect($conn) or die('Could not connect: ' . mysql_error()); mysql_query($sql_update) $sql_update "UPDATE users SET datetime=date("Y.m.d - H:i:s") WHERE username='$_SESSION[username]'") or die ("could not execute the query."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/101929-solved-how-to-update-an-existing-field-php-and-mysql-4-lines-of-code-ugh/#findComment-521651 Share on other sites More sharing options...
MesaFloyd Posted April 20, 2008 Author Share Posted April 20, 2008 Hi Blade, thanks for looking, I replaced my four lines of code with your code (without your <?php and ?> ) ...still a Blank screen.... Just for a sanity check, I // out your and my code, and goes back to working my mind is 'boggled' Quote Link to comment https://forums.phpfreaks.com/topic/101929-solved-how-to-update-an-existing-field-php-and-mysql-4-lines-of-code-ugh/#findComment-521657 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 <?php function displayLogin() { global $logged_in; if($logged_in) { mysql_connect($conn) or die('Could not connect: ' . mysql_error()); $date = date("Y.m.d - H:i:s"); $sql_update = "UPDATE users SET datetime='{$date}' WHERE username='{$_SESSION['username']}';"; mysql_query($sql_update) or die ("could not execute the query:". mysql_error()); echo "<br><h1>Logged In!<br><br></h1>"; echo "Hello <b>$_SESSION[username]</b> you are logged in.<br>"; } } displayLogin(); ?> sorry, Blade. Your code was kinda messed up. No offense. Quote Link to comment https://forums.phpfreaks.com/topic/101929-solved-how-to-update-an-existing-field-php-and-mysql-4-lines-of-code-ugh/#findComment-521662 Share on other sites More sharing options...
DeanWhitehouse Posted April 20, 2008 Share Posted April 20, 2008 Yer, mine should of worked though, i think Quote Link to comment https://forums.phpfreaks.com/topic/101929-solved-how-to-update-an-existing-field-php-and-mysql-4-lines-of-code-ugh/#findComment-521667 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 mysql_query($sql_update) $sql_update "UPDATE users SET datetime=date("Y.m.d - H:i:s") WHERE username='$_SESSION[username]'") or die ("could not execute the query."; you were calling sql_update before you defined it. Quote Link to comment https://forums.phpfreaks.com/topic/101929-solved-how-to-update-an-existing-field-php-and-mysql-4-lines-of-code-ugh/#findComment-521671 Share on other sites More sharing options...
DeanWhitehouse Posted April 20, 2008 Share Posted April 20, 2008 o yer, didn't notice that. My bad. Quote Link to comment https://forums.phpfreaks.com/topic/101929-solved-how-to-update-an-existing-field-php-and-mysql-4-lines-of-code-ugh/#findComment-521673 Share on other sites More sharing options...
MesaFloyd Posted April 20, 2008 Author Share Posted April 20, 2008 Blade and Jonsjava Thanks to you both. Your scripting was very helpful.... I did a bit of adjsting for my code and works now I appreciate both your cleverness.... Jons... I had already referred to the DB so I didnt need your connect method I just needed the way you posted the date to mysql... worked like a charm Eternally grateful Floyd Quote Link to comment https://forums.phpfreaks.com/topic/101929-solved-how-to-update-an-existing-field-php-and-mysql-4-lines-of-code-ugh/#findComment-521682 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.