Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → I need your help, something I know one of you can do...
I need your help, something I know one of you can do...
2004-03-07, 2:31 PM #1
OK, I need a REALLY simple script or 2 written in PHP. It just needs to accept an input string, and store it. Then another to get the string. Basicly I want to have some software I wrote that will be running on my laptop to go to a url such as:

http://www.twistedrat.com/moo.php?lala=Server is up!

And then I can get that value back on my site, maybe stored in a text file on the web server. And the web server is with 1and1 if that makes any difference. I know one of you could code that up in a minute or two, and if you could I would be VERY grateful. Thanks in advance.

------------------
http://www.sporkaudio.com
gbk is 50 probably

MB IS FAT
2004-03-07, 2:34 PM #2
Also if something like this has already been written, could you please link me to it. And please ignore UBB's stupid auto-link thing.

------------------
http://www.sporkaudio.com
gbk is 50 probably

MB IS FAT
2004-03-07, 3:34 PM #3
You could do it easily using MySQL - but then again that's pretty much all I know how to do with PHP.

Let's use your URL : http://www.twistedrat.com/moo.php?lala=Server%20is%20up

You can get the variable lala using $_GET['lala'] or simply $lala if your server has registered globals turned to on.

Here's a script that will insert the stuff into a MySQL table with an autoincrement row called "Id" and a varchar row called "lala":
<?php
$connect = mysql_connect("localhost", "username", "password") or die("Could not connect to database!");
$result = mysql_select_db("databasename") or die("Could not select database!");

$sqlquery = "INSERT INTO table VALUES('', '". $_GET['lala'] ."')";
$queryresult = mysql_query($sqlquery) or die("SQL screwed up!");
echo "Data sucessufully inserted";
?>

And to retrieve the data, using a url such as http://www.twistedrat.com/moo.php?Id=6 :
<?php
$connect = mysql_connect("localhost", "username", "password") or die("Could not connect to database!");
$result = mysql_select_db("databasename") or die("Could not select database!");

$result = mysql_query("SELECT lala FROM table WHERE Id='$_GET['Id']'",$connect);

while ($myrow = mysql_fetch_assoc($result)) {
echo $myrow['lala'];
}
?>

[http://forums.massassi.net/html/smile.gif]

------------------
When guitars are outlawed, only outlaws will have guitars.

[This message has been edited by MaD CoW (edited March 07, 2004).]
2004-03-07, 4:11 PM #4
That's awesome, but I only have one MySQL DB, and it's in use. I'd rather use a plain text file, since it's just a simple thing.

------------------
http://www.sporkaudio.com
gbk is 50 probably

MB IS FAT
2004-03-07, 4:12 PM #5
Why don't you just add a new table to your DB? No need to create a new one [http://forums.massassi.net/html/tongue.gif]

------------------
When guitars are outlawed, only outlaws will have guitars.
2004-03-07, 4:21 PM #6
All I know is HTML [http://forums.massassi.net/html/redface.gif]

How would I add a table?

------------------
http://www.sporkaudio.com
gbk is 50 probably

MB IS FAT
2004-03-07, 4:25 PM #7
Oh crap... that would depend on your server. My server uses phpMyAdmin, which I believe is used on many web servers. It's basically point and click to add a table to your database. You could contact your server administrator, or see if anyone else here would know how to insert data into a text file.

------------------
When guitars are outlawed, only outlaws will have guitars.
2004-03-07, 4:33 PM #8
Code:
<html>
<body>

<?php
if($lala = $_GET['lala'])
{
	$handle = fopen("log","a");
	fwrite($handle,"$lala<br>");
	fclose($handle);
	echo "Wrote to log file.";
}
else
{
	echo "Log file contents:<br>";
    	echo readfile('log');
}
?>

</body>
</html>


Run the script as moo.php?lala=whatever to put "whatever" in the log file. Run it as moo.php to print the log file.
2004-03-07, 4:33 PM #9
Alright I'll see what I can do, Thanks Mad Cow!

If anyone knows how to do this with a text file let me know.

------------------
http://www.sporkaudio.com
gbk is 50 probably

MB IS FAT
2004-03-07, 4:50 PM #10
Argath, that works great, except for one thing. When I give it a new string thats the only thing I want it to show. This is going to give server status on my homepage. Right now it just adds a new line, and then at the bottom of it, it prints how many bytes the file is. I just want it to output what I gave it. Thanks again. [http://forums.massassi.net/html/smile.gif]

------------------
http://www.sporkaudio.com
gbk is 50 probably

MB IS FAT
2004-03-07, 5:21 PM #11
Change the "a" in fopen to "w". That'll overwrite the file every time you insert a new value.

Oh, you can also remove the "echo" from "echo readfile('log')". The echo just prints the file size.

[This message has been edited by Argath (edited March 07, 2004).]
2004-03-07, 6:07 PM #12
Ah PERFECT!

Thank you VERY much. You get a whole box of cookies [http://forums.massassi.net/html/tongue.gif]

------------------
http://www.sporkaudio.com
gbk is 50 probably

MB IS FAT

↑ Up to the top!