Jump to content

Two Questions


Gunnar J

Recommended Posts

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

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

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

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

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

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

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

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

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

Archived

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

×
×
  • Create New...