Jump to content

Link Pressed


kirbyweb

Recommended Posts

  • Replies 58
  • Created
  • Last Reply

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

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

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

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

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

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

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

if(!_POST) {//stuff you want to run only if the button was clicked goes here}

Link to comment
Share on other sites

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

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

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

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

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...