|
PCCS MySQLDatabase Admin Tool version 1.3.4
|
/ -> mysqldb_create_motdscript.php
1 <?php
2 /************************************************************************
3 PCCS MySQLDatabase Admin Tool
4 Copyright (C) Chauncey Thorn
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA , USA.
19 **************************************************************************/
20
21 /////////////////////////////////////////////////////////////////////////////// 22 // Create Message of the day script 23 // Create users table and insert this users data 24 // no need to modify unless you like hacking 25 // bugs report to cthorn 26 // 27 // file inculded from mysqldb_process_webuser.php 28 /////////////////////////////////////////////////////////////////////////////// 29
30 // Fixed bug where $db_name should have be used instead of $webdatabase 31
32 $motd_filename="motd.php";
33 if(!$motd = fopen($appfiledir . $motd_filename,"w")) {
34 print "Couldn'tfile";
35 } else {
36 fputs($motd,"<?php\n//** Generated by PCCS-MyAppGen\n");
37 fputs($motd,"//////////////////////////////////////////////////////////////////////////////\n");
38 fputs($motd,"//\n");
39 fputs($motd,"require('dbinclude.php');\n");
40 fputs($motd,"if(!\$numberofquotes = mysql_db_query(\$db_name,\"SELECT * FROM motd\")) {\n");
41 fputs($motd," print \"ERROR: \" . mysql_error();\n");
42 fputs($motd," } else {\n");
43 fputs($motd," \$getnumber = mysql_num_rows(\$numberofquotes);\n");
44 fputs($motd," srand((double)microtime()*100000);\n");
45 fputs($motd," \$id = rand(1,\$getnumber);\n");
46 fputs($motd," if(!\$query = mysql_db_query(\$db_name,\"SELECT * FROM motd where id = \$id\")) {\n");
47 fputs($motd," print \"ERROR: \" mysql_error();\n");
48 fputs($motd," } else {\n");
49 fputs($motd," \$row = mysql_fetch_array(\$query);\n");
50 fputs($motd," \$id = \$row[\"id\"];\n");
51 fputs($motd," \$message = \$row[\"message\"];\n");
52 fputs($motd," print \"<center>\$message</center>\";\n");
53 fputs($motd," }\n");
54 fputs($motd," }\n");
55 fputs($motd,"\n");
56 fputs($motd,"//\n");
57 fputs($motd,"//////////////////////////////////////////////////////////////////////////\n");
58 fputs($motd,"?>\n");
59 fclose($motd);
60
61 }
62
63 $create_motdtbl_query = "CREATE TABLE motd (
64 id int(11) DEFAULT '0' NOT NULL auto_increment,
65 message varchar(255) NOT NULL,
66 PRIMARY KEY (id))";
67
68 if(!mysql_db_query($db_name,$create_motdtbl_query)) {
69 print "ERROR :" . mysql_error();
70 }
71
72 // Put some data in the table... 73 // insert some text for demo ... 74
75 for($i=0; $i< 5; $i++) {
76 $create_insert_query = "INSERT INTO motd VALUES ('','This is message of the day number $i')";
77 if(!mysql_db_query($db_name,$create_insert_query)) {
78 print "ERROR :" . mysql_error();
79 }
80 }
81
82
83 ?>
| |