Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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