Profile View Update [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 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'"

Related

Activity logs using PHP Mysql [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 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())

Update record number unexpectedly fails [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 7 years ago.
Improve this question
I am trying to get this to update a record and was wondering why I cant get this to work?
I can write a new record no problem but the update doesn't work; is it something simply I am missing?
else {
echo "ID NOT EMPTY-";
//---inside else statement shows this echo and the $id number printed on screen WHERE should have varible $ID but I changed it to debug
echo "$id";
$SQLstring3 = "UPDATE $Tablename SET(blank='1') WHERE(id='5')";
$QueryResult = #mysql_query($SQLstring3, $DBConnect);
}
I think the problem might be the way you are using SET and WHERE. Putting them the parentheses () immediately following them might make them seem like a MYSQL function, which it tries to execute. What you have is this:
"UPDATE $Tablename SET(blank='1') WHERE(id='5')";
Try removing the parentheses:
"UPDATE $Tablename SET blank='1' WHERE id='5'";

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'"

I have error in folloing code of php for 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 8 years ago.
Improve this question
the below query is not working
$query= mysql_query('SELECT * FROM Registration WHERE name="'.$_POST['Username'].'" & password="'.$_POST['Password']);
Use the word SET once only in your query. And separate each data by comma(,).
You should also consider escaping the string of your variables before using them into your query.
If you are using MySQLi, you can do this:
$username=mysqli_real_escape_string($connection,$_POST['Username']);
$password=mysqli_real_escape_string($connection,$_POST['Password']);
$city=mysqli_real_escape_string($connection,$_POST['City']);
$state=mysqli_real_escape_string($connection,$_POST['State']);
$country=mysqli_real_escape_string($connection,$_POST['Country']);
$userid=mysqli_real_escape_string($connection,$_POST['user_id']);
$query="UPDATE Registration SET name='$username', password='$password', city='$city', state='$state', country='$country' WHERE id='$userid'";
mysqli_query($connection,$query); /* EXECUTE QUERY */
Use , instead of set between each fields. Use this altered query,
('UPDATE Registration SET name="'.$_POST['Username'].'" , password="'.$_POST['Password'].'" , city="'.$_POST['City'].'" , state="'.$_POST['State'].'" , country="'.$_POST['Country'].'" WHERE id='.$_POST['user_id']);

Insert a single value into database table which has multiple columns [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 couldn't find an anwser on google, so here's my question.
Let's say, I have a table which has name,lastName,Age columns.
What I want to do, is insert only "name" into the table.
I have a function
function c_mysqlInsert($ptable,$pvaluename,$pvalue,$database=""){
global $con_dbaccounts;
$dbname = ($database=="")?$con_dbaccounts:$database;
$con = c_dbconnect($dbname);
mysql_query($con,"INSERT INTO $ptable ($pvaluename) VALUES('$pvalue')");
}
/**
which doesn't seem to insert any new things into the $pdbtable, even when $ptable, $pvaluename and $database are all correct. It does connect to the database $database.
I thought it would create a new row with $pvalue and the other columns empty (or NULL), but it doesn't.
So I guess I can't do it this way - call c_mysqlInsert function multiple times to insert into all three columns, so is there any other way I could make this function work?
Your insert statement has the $pdbtable variable but the variable passed into your function is $ptable. Change the variable in your insert and you should be golden.

Categories