Gunnar J Posted March 24, 2008 Share Posted March 24, 2008 OK1. How do you make forms with PHP?2. Can someone explain the process of how to make it so you have a variable and then how to make the variable go up when you click a button? Link to comment Share on other sites More sharing options...
Ingolme Posted March 24, 2008 Share Posted March 24, 2008 1. You just write the HTML for the form:<form action="[something]" method="post"><p><input type="text" name="field"></p></form>2. I haven't heard of a variable ever "go up" before. A variable simple contains data of some kind:$V = "A string variable";$N = 35; //This is a numerical variable Link to comment Share on other sites More sharing options...
Gunnar J Posted March 24, 2008 Author Share Posted March 24, 2008 Is it possible to change one variable ( like 1 ) go up 1 ( into 2 ) ? If not, how do they do...... those pokemon games that are online? Link to comment Share on other sites More sharing options...
Cod-nes Posted March 24, 2008 Share Posted March 24, 2008 it is easy as this: <?php$V++;?> check this page for more help:http://w3schools.com/php/php_operators.asp Link to comment Share on other sites More sharing options...
Synook Posted March 24, 2008 Share Posted March 24, 2008 The correct term for "go up" is "increment" ("go down" is "decrement")The $V++ and $V-- operators are the postcrement operators (postincrement and postdecrement)There is also ++$V and --$V (precrements; preincrement and predecrement) Link to comment Share on other sites More sharing options...
Gunnar J Posted March 24, 2008 Author Share Posted March 24, 2008 Is it possible for me to store the variable in another php file and open it then change it then put it back and it stays the same way?eg I create a file named A.php and in it it states A=1, I open the file and change A to 2 and then close it, then I come back a year later and A is still 2 in A.php? Link to comment Share on other sites More sharing options...
Synook Posted March 24, 2008 Share Posted March 24, 2008 You'll have to store the variable in a file e.g.Page 1 $a = 2;file_put_contents("storea.txt", $a); Page 2 $a = file_get_contents("storea.txt");echo $a; //Will echo "2" or in a database e.g.Page 1 //Connect to your database here$a = 2;mysql_query("UPDATE var_table SET value = $a WHERE name = \"a\""); Page 2 //Connect to your database here$result = mysql_query("SELECT value FROM var_table WHERE name = \"a\"");$var = mysql_fetch_assoc($result);$a = $var['value'];echo $a //Will echo 2 Link to comment Share on other sites More sharing options...
Gunnar J Posted March 24, 2008 Author Share Posted March 24, 2008 You'll have to store the variable in a file e.g.Page 1$a = 2;file_put_contents("storea.txt", $a); Page 2 $a = file_get_contents("storea.txt");echo $a; //Will echo "2" or in a database e.g.Page 1 //Connect to your database here$a = 2;mysql_query("UPDATE var_table SET value = $a WHERE name = \"a\""); Page 2 //Connect to your database here$result = mysql_query("SELECT value FROM var_table WHERE name = \"a\"");$var = mysql_fetch_assoc($result);$a = $var['value'];echo $a //Will echo 2 Ok, Ill try that and see if it works Link to comment Share on other sites More sharing options...
Synook Posted March 24, 2008 Share Posted March 24, 2008 Uh you'll need to do a few other things before it will work:for the file, create a file in the same directory called storea.txtFor the database one, create a database and insert mysql_connect() and mysql_select_db() with the information you set up, then create a table called var_table with two columns: name and value.By the way, you could also store the value in a cookie, but it probably wouldn't last a year as clients would delete it. Link to comment Share on other sites More sharing options...
Gunnar J Posted March 24, 2008 Author Share Posted March 24, 2008 Uh you'll need to do a few other things before it will work:for the file, create a file in the same directory called storea.txtFor the database one, create a database and insert mysql_connect() and mysql_select_db() with the information you set up, then create a table called var_table with two columns: name and value.By the way, you could also store the value in a cookie, but it probably wouldn't last a year as clients would delete it.ya lol, but I was thinking that I might be able to open the file, change the variable, and close the file and then when I look at the file the variable is different... heres what I got...storea.php<?php$a = 1;?>testing.php<?php$a = file_get_contents("storea.txt");$a++;file_put_contents("storea.php", $a");?> Link to comment Share on other sites More sharing options...
Synook Posted March 24, 2008 Share Posted March 24, 2008 Oh right - you could do that. The code is correct, except for a syntax error and a logic error at file_put_contents() - can you see them? Link to comment Share on other sites More sharing options...
Gunnar J Posted March 24, 2008 Author Share Posted March 24, 2008 Oh, did I put .php instead of .txt? Or is it the other way aroung? Cuz I have a file named storea.php and did I put " after , $a yaaaaaaaaa tahts it, lemme try again Link to comment Share on other sites More sharing options...
justsomeguy Posted March 24, 2008 Share Posted March 24, 2008 The $V++ and $V-- operators are the postcrement operators (postincrement and postdecrement)There is also ++$V and --$V (precrements; preincrement and predecrement)So if you have postcrement and precrement operators, what do you call the operators that exincrement and exdecrement? Would those be the excrement operators? Because, if so, then I'm going to need to work up definitions for exincrement and exdecrement. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.