Join 150,151 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,362 people online right now. Registration is fast and FREE... Join Now!
How do you increment/decrement/edit values in a database? I'm still learning, but I want to create a test button that will increase +1 and save it, then log out and in to test it!
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Please post like this:
Thank you for helping us helping you.
Here is a decent article on working with database data with PHP
UPDATE stylepoints SET stylepoints=stylepoints=stylepoints+1;
}
I know the stylepoints variable is working, because it says "0" when I log in. I also gave enough information for someone to help me. All you need to know is the variable name.
I'm a little confused as to what you're trying to do. The "code" you posted is just an SQL query inside a PHP if block. There's no hint of any code to connect to an actual database. Are we to assume you just omitted that?
As for your actual query (since this is the database forum), it isn't going to work the way you want. For starters, it's updating every row in the stylepoints table, which probably isn't what you want, unless the table only has one row. Second, you have stylepoints=stylepoints=stylepoints+1, which actually doesn't increment stylepoints. Did you mean just stylepoints=stylepoints+1? What you posted actually sets stylepoints ot 0 (at least in MySQL) because it does an equality comparison between stylepoints to stylepoints+1, which is always false, and casts the value to an integer zero.
I'm omitting code, and that was a typo. Thanks for spotting that, Its correct in my code tho.
Basically, I go to my website. I type in username and password. Page refreshes. It says Hello admin! Rank: Administrator , Style Points = 0 Style Points = 0 shows up, so that must be working.
Under the nicebutton2 line, I created the exact same line, but named it nicebutton3 with name="Increment"
then I used my if statement I showed you to make it increment when I click the button. The button shows up just fine, but I cant even load my page because I have a code error in the if statement.
I only want to increment admin's stylepoints variable by 1, no one elses.
I hope I gave you all you need to know. variable stylepoints for user "admin" who is under the rank Administrator ( which shouldnt matter, I think)
This post has been edited by Sonastylol: 21 Jul, 2008 - 06:52 PM
This is for the guys at gamefaqs.com , and you guys too, thanks
CODE
<?php
session_start(); include("config.php"); include ('header.php'); include ('nav.php'); include ('banner.php'); include ('side.php'); include ('index-content.php'); include ('include-challenge.php'); include ('loginheader.php');