I want to update my users last log in in the database :

<input name="login" type="submit" id="login" onclick="<?php mysql_select_db($database_web, $web) or die("Error : " . mysql_error()); mysql_query("UPDATE users SET timp='NOW()' WHERE username='$user'")or die("Error : " . mysql_error());?>" value="LogIn" />

this is my code but it doesent update the table :|
if i replace the NOW() with a manual time and date it works

Member Avatar for diafol

You can't run php from an onclick (js) attribute.

You can't run php from an onclick (js) attribute.

i dont get it....
it works if i set time and date manualy....so the php works right ?

Member Avatar for diafol
<?php mysql_select_db($database_web, $web) or die("Error : " . mysql_error()); mysql_query("UPDATE users SET timp='NOW()' WHERE username='$user'")or die("Error : " . mysql_error());?>

This is run on the server before you see the page. If the form is sent to itself, then it will be run again - nothing to do with onclick.

<?php mysql_select_db($database_web, $web) or die("Error : " . mysql_error()); mysql_query("UPDATE users SET timp='NOW()' WHERE username='$user'")or die("Error : " . mysql_error());?>

This is run on the server before you see the page. If the form is sent to itself, then it will be run again - nothing to do with onclick.

stil not updateing :(
i enterd the script in the page...no events
whit the NOW() it doesen't update
if i enter "Ex:2011-06-25" in sted of the NOW() it works

Member Avatar for diafol

Listen, onclick is for js NOT php. php will not run from onclick.

php will run wherever you put it in the page BEFORE you see it.

You must use $_POST variables (or even $_GET is form set to get) to retrieve data sent by a form.

i need the php to update the mysql database with the curent time and date of the user that loged in....but it doesent


what do i need $_POST/GET for.....i allready use it to retreave the $user in the php script

Member Avatar for diafol

i need the php to update the mysql database with the curent time and date of the user that loged in....but it doesent

When the user logs in, update using the POST variable. If you want to use onclick, you'll have to use Ajax.

This piece of code is wrong:

<input name="login" type="submit" id="login" onclick="<?php mysql_select_db($database_web, $web) or die("Error : " . mysql_error()); mysql_query("UPDATE users SET timp='NOW()' WHERE username='$user'")or die("Error : " . mysql_error());?>" value="LogIn" />

Good luck.

ok...i understand this
i deleted this

<input name="login" type="submit" id="login" onclick="<?php mysql_select_db($database_web, $web) or die("Error : " . mysql_error()); mysql_query("UPDATE users SET timp='NOW()' WHERE username='$user'")or die("Error : " . mysql_error());?>" value="LogIn" />

and moved this

<?php mysql_select_db($database_web, $web) or die("Error : " . mysql_error()); mysql_query("UPDATE users SET timp='NOW()' WHERE username='$user'")or die("Error : " . mysql_error());?>

in the page body
but it doesent update

Remove quotes from NOW() and it will work:

"UPDATE users SET timp=NOW() WHERE username='$user'"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.