0

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

3
Contributors
9
Replies
11
Views
6 Years
Discussion Span
Last Post by cereal
0

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

0

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 ?

0
<?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.

0
<?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

0

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.

0

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

0

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.

0

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

Edited by foxwizzy: n/a

1

Remove quotes from NOW() and it will work:

"UPDATE users SET timp=NOW() WHERE username='$user'"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.