Activity logs using PHP Mysql [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 months ago.
Improve this question
I'm trying to do an activity log wherein it saves the time when you logged in an account. The problem is the id saves the value while action saves "0" and datetime saves "0000-00-00 00:00:00" in the database. What's the problem with the code?
date_default_timezone_set('Asia/Manila');
$time = date('m/d/y h:iA', time());
$log = 'logged in';
$sql = "INSERT INTO logs VALUES (
id = '1',
action='has logged in',
datetime=now()
)
";

Try this:
INSERT INTO logs (id,action,`datetime`) VALUES ('1','has logged in',now())

Related

gRPC Protobuf's Timestamp.FromDateTime() returns null on PHP [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I cant get my head around what I am doing wrong here.
use Google\Protobuf\Timestamp;
$timestamp = new Timestamp();
$dt = Carbon::now();
$pt = $timestamp->fromDateTime($dt);
Carbon is a simple PHP API extension for DateTime so it should work but instead I get a null value for $pt
I was doing it wrong, in case for future reference, the way is done is so:
use Google\Protobuf\Timestamp;
$timestamp = new Timestamp();
$dt = Carbon::now();
$timestamp->fromDateTime($dt);
and then use the $timestamp variable as needed.

MySQL Date between query [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Why BETWEEN '2020-02-22 00:00:00' AND '2020-02-22 23:59:59' is working (getting Data)?
AND why BETWEEN '2020-02-22' AND '2020-02-22' is not working (Not getting Data)?
Edited: Got it. I forgot to add date(created_at) instead of created_at
You may use the whereBetween method
It verifies that a column's value is between two values.
Expl
$from = date('2018-01-01');
$to = date('2018-05-02');
Model::whereBetween('dateColumn', [$from, $to])->get();
Or
Model::where('dateColumn', '>=', $from)->where('dateColumn', '<=', $to)->get();

Profile View Update [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to create a query which will update each person's profile views when a member accesses their profile. For some reason it does not update, I am sure it would have worked. Here is my lines:
<?php
$name = $_REQUEST['username'];
$profile = mysql_query("SELECT * FROM users WHERE user_name='$name'");
$uprofile = mysql_fetch_assoc($profile);
$username = $uprofile['user_name'];
$profilev = $uprofile['profile_views'];
mysql_query("UPDATE users SET profile_views +1 WHERE user_name='$name'");
?>
So, On my profile, It displays their username successfully, and it displays the default value of the database for profile_views which ofcourse, is 0. so it is reading correctly, I am just having issues updating the users profile_views.
You have a mistake try
"UPDATE users
SET profile_views = profile_views +1
WHERE user_name='$name'"

Checking userlevel but it won't work [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm not the best at php and mysql and i'm still learning however i have this userlevel variable which i define in my session
and if i message it back to myself using
<?php echo"$session->userlevel"; ?>
It'll work, it'll tell me that me that my userlevel is "0" which it should be however when i'm using an if statement to check it won't work?
<?php
if ($_SESSION['userlevel'] = 0) {
echo "Userlevel 0 was found!";
}
?>
Any though
if($_SESSION['userlevel'] = 0)
should be
if($_SESSION['userlevel'] == 0)
Otherwise you don't check, you assign the value 0 to $_SESSION['userlevel']

Delete Query Not Deleting [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm wondering why the first delete query won't work, when the second does?
if(isset($_POST['accept request' . $user_from])) {
$delete_request = mysql_query("DELETE FROM friend_requests WHERE user_from='$user_from' AND user_to='user_to'");
header("location: friend_requests.php");
echo "<br /><br />You are now friends with " . $user_to;
}
if(isset($_POST['ignorerequest' . $user_from])) {
$delete_request = mysql_query("DELETE FROM friend_requests WHERE user_from='$user_from' AND user_to='$user_to'");
header("location: friend_requests.php");
echo "Friend Request Declined";
}
Please ignore the fact that they're not prepared, and that it's a security issue. I purely want to know why the first delete request doesn't work (yes, the if gets triggered properly)
your missing the dollar sign on your user_to variable
"DELETE FROM friend_requests WHERE user_from='$user_from' AND user_to='$user_to'"

Categories