Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

php/mysql update variable by 1

  • 04-04-2011 12:01pm
    #1
    Closed Accounts Posts: 5,824 ✭✭✭


    trying to get mysql to update by +1 if a user uploads an image, or decrease by 1 if they delete an image etc.

    $update = mysql_query("UPDATE uploaders SET image = image + 1 WHERE username = '$user'");

    i have $user set as

    $user = $_SESSION;

    ive been using the $user variable on plenty of other pages and no problems there..

    any suggestions?


Comments

  • Closed Accounts Posts: 5,824 ✭✭✭RoyalMarine


    been trying something different still with no luck yet.

    $update = mysql_query("UPDATE uploaders SET image = image+1 WHERE id ='$_SESSION[id]'");


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    What is the data type of the image column?


  • Closed Accounts Posts: 5,824 ✭✭✭RoyalMarine


    its in int(11) type


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Are you sure that $_SESSION exists.

    Have you printed it out to see if so?

    Maybe you are forgetting your session_start() at the top of your PHP file.


  • Closed Accounts Posts: 5,824 ✭✭✭RoyalMarine


    i have the session_start() in an include file.

    in the same script, im using this
    $foldername = $_SESSION;

    and it works when i upload an image to a directory with $foldername in it.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    i have the session_start() in an include file.

    in the same script, im using this
    $foldername = $_SESSION;

    and it works when i upload an image to a directory with $foldername in it.
    What's the actual error. Can you print out the mysql last error string.


  • Closed Accounts Posts: 5,824 ✭✭✭RoyalMarine


    thats the thing it doesnt give any error either :/


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    so what debugging have you done?


  • Closed Accounts Posts: 5,824 ✭✭✭RoyalMarine


    got it working with this

    if (isset($_SESSION))

    $update = mysql_query("UPDATE uploaders SET image =image+1 WHERE username ='$_SESSION[user]'");


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    got it working with this

    if (isset($_SESSION))

    $update = mysql_query("UPDATE uploaders SET image =image+1 WHERE username ='$_SESSION[user]'");
    Well, in that case it couldn't have been set like I said above. You are hiding the problem there. I'd check your work flow/logic if I were you


  • Advertisement
  • Closed Accounts Posts: 5,824 ✭✭✭RoyalMarine


    yeah i found where i messed up. i was putting the sql statement above the if(isset) statement.


Advertisement