justsomeguy Posted November 20, 2009 Share Posted November 20, 2009 Your variables work? Did you understand what I told you to do? What did you do? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 I echoed out the variables, why is there one I missed? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 Oh I do not think $last, or $extra_Time works, I am not sure though they did not show up in echo. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 Ok they all work. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 20, 2009 Share Posted November 20, 2009 Right, so get the values of all of the variables and then walk through your code substituting in the values to figure out why the code goes into the if statements to update the database, and what it updates with. I'm talking about just using a pencil and paper to keep track of variable values while you go through each line in the code to see what it's doing and why. Based on what the values are, you should be able to determine why the code is doing what it's doing, i.e. why the if statements are or are not being executed. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 Huh? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 20, 2009 Share Posted November 20, 2009 You need to debug the code. In this case, that means manually walking through it. Print out the code or something, go through it line by line and keep track of what the different values for the variables are. Consider yourself the computer, you're executing the code. Keep a list of the variables and their current values, and walk through each line of the code so that you can understand what it's doing. The output you printed earlier for the variables will tell you what the starting values are. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 It prints out what its suppose to do, its just the money goes over the limit, then I have to refresh the page for it to go back to 500. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 20, 2009 Share Posted November 20, 2009 OK. And I assume you want to know how to stop it going over the limit, right? So that means you have to figure out why it's going over the limit, right? When I want to know why my code is doing what it's doing I keep track of variables on a piece of paper and walk through the code myself. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 Well the variables are working, but I cannot figure out why, maybe I should find a new forum. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 I mean, do you know why it is going over 500? the bank is at 0, but when I refresh the page, it goes over 500, when I refresh it again, it goes back to 500. Link to comment Share on other sites More sharing options...
thescientist Posted November 20, 2009 Share Posted November 20, 2009 Well the variables are working, but I cannot figure out why, maybe I should find a new forum.JSG is being very pragmatic in his approach to helping you, but why aren't you following his advice? What he's trying to get you to understand is that there is an element in your logic that is failing to keep your code from executing properly. It's just as discouraging for us because we are trying to help you, but you have to grasp the fundamentals of programming logic first. The key is to understand that computers can only do what they're told to do. You have to be very explicit in your logic, and literally take it one step at a time. I know I recommended that you try writing out the code as if you were giving someone verbal instructions (step by step), and then convert each step into a line of code. Trace your variables as you go along and see if what you're implementing works. The variables don't really do anything themselves, they just store information. But you can compare them to other variables to induce logic that can make your code go one way or the other. So if you're variables are "working", then what do you think is causing your code to fail? It has something to do with the bank reaching 500, right? So what do you think it should do when you want it to make a decision based upon the users current bank account, and the imposed limit? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 Its money not bank, if the money is smaller then 500 and the bank is == to 0, then its stops at 500, its not doing that it goes over 500, and none of your advises are helping. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 20, 2009 Share Posted November 20, 2009 You don't think it's helpful to learn how to debug your code? It's not going to teach you anything if I tell you why your script isn't working the way you want it to, you're just going to come back with another question for a similar issue and still not know how to debug your own code. What do you think I do when I have a problem, do you think the reason I don't post questions here is because I never have problems?If you're just looking for people to solve all of your problems for you then, yeah, you're in the wrong forum. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 Well is the $money > 0 suppose to be there? Link to comment Share on other sites More sharing options...
thescientist Posted November 20, 2009 Share Posted November 20, 2009 This is your code with its own logic. You tell us. Sorry if it seems like we're being difficult, but there really is no better, or easier way to learn, short of having it done for you, which will certainly not make you a better programmer.Write out your logic, I think by this point we've all kind of lost the gist of what you're trying to do. Make a step by step list. Something, anything; meet us halfway please, so we can continue to try and help you. Link to comment Share on other sites More sharing options...
alexnofue Posted November 20, 2009 Share Posted November 20, 2009 Hi, when i became too lost with the code, i check the indentation of the whole code, then comment it all.with the code fully commented i start to uncomment the lines in the first level while printing the variables.if the problem its not there go for the second level and so on.this of course works on rather small codes. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 OK I think I fixed it, not sure how.Now for the last question, how do I make a form only submit when I click the button, not when I click the button and then refresh. Link to comment Share on other sites More sharing options...
chibineku Posted November 20, 2009 Share Posted November 20, 2009 if(!_POST) {//stuff you want to run only if the button was clicked goes here} Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 What is the ! for? Link to comment Share on other sites More sharing options...
chibineku Posted November 20, 2009 Share Posted November 20, 2009 It's the 'not' operator. It makes the brackets evaluate to true in the absence of the $_POST superglobal array (which means that there was no form submission). Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 So like this?if (!$_POST['train']) { Link to comment Share on other sites More sharing options...
chibineku Posted November 20, 2009 Share Posted November 20, 2009 Missing a closing ), but yeah. You don't even need to specify any of the $_POST variables - !$_POST checks for the presence of the array. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 20, 2009 Author Share Posted November 20, 2009 No this is not working, I want to make it so if the page is refreshed, whether the form was submitted or not, it will not do anything.So the only way the form gets submitted is if the submit button was pressed, so if it was pressed and you click refresh it does not do anything. Link to comment Share on other sites More sharing options...
chibineku Posted November 20, 2009 Share Posted November 20, 2009 You will actually want to discard what I said earlier and do this:if($_POST) {//put everything in here that you want to run only IF the submit button IS pushed} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.