Trouble updating a particular user in a mysql database -
im trying update particular user logged in using update mysql command, instead going first user in database itself, if can id appreciate it
edit: im wanting increment number of 'items' user has, code below going first user in database
<?php session_start(); $dbhost = 'localhost'; $dbuser = ''; $dbpass = ''; $dbname = ''; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('error connecting mysql'); mysql_select_db($dbname); $query = sprintf("update users set item = item + 1 ", mysql_real_escape_string($_post['item'])); mysql_query($query); ?>
your sprintf()
call has parameter, no placeholder:
$query = sprintf("update users set item = item + 1 ", mysql_real_escape_string($_post['item']));
probably supposed following, assuming int
column named item
$query = sprintf("update users set item = item + 1 item = %d ", mysql_real_escape_string($_post['item']));
update
if trying target specific user only, need user's id or username in $_post
instead of item
. you'll need post output of var_dump($_post)
see values you've received in post.
assuming string username
, use:
$query = sprintf("update users set item = item + 1 username = '%s' ", mysql_real_escape_string($_post['username']));
Comments
Post a Comment