
|
View Full Version : submitting a mysql query without phpmyadmin
ethereality 08-21-2005, 09:57 PM I'm creating a message board administration panel for role-playing games. For the script to be sucessful, it needs to have an option to add message boards. But, since I don't fully understand how to do what I want, I need to post it here.
So, what I need help on is running a mysql query without the use of phpMyAdmin.
Is it possible for a user to submit a query and have the script connect to the database and add the table in the query?
The query would be something like this:
CREATE TABLE table_name (
id integer NOT NULL auto_increment,
parent integer DEFAULT '0',
thread integer DEFAULT '0',
name tinytext,
email tinytext,
subject tinytext,
message text,
date timestamp,
ip char(15),
PRIMARY KEY (ID)
);
Also.. how would I make a script that would post information to the TOP of a file, instead of the BOTTOM.
azizny 08-21-2005, 10:11 PM You can run a sample query in PHPMYADMIN (which I see you already did) and then:
Connect to MYSQL via PHP...
Query the statement:
@mysql_query("CREATE TABLE table_name (
id integer NOT NULL auto_increment,
parent integer DEFAULT '0',
thread integer DEFAULT '0',
name tinytext,
email tinytext,
subject tinytext,
message text,
date timestamp,
ip char(15),
PRIMARY KEY (ID)
);");
easy and simple..
I dont understand the last question.
Peace,
ethereality 08-21-2005, 10:41 PM And with that code I should be able to create a form and submit it from there right?
And for the last question..
A sample of this would be a user submitting text into a textbox, say something labled "description", and it would submit everything that the user typed into "description.php" at the top. I say the top because everything is defined in variables, and the main coding is at the bottom. I assume you know that variables have to be written above the code using the variable.
azizny 08-22-2005, 06:06 AM Originally posted by ethereality
And with that code I should be able to create a form and submit it from there right?
No, that code only shows you how to create a table from PHP (which I thought you wanted)...
But if you want to have those as fields from a post, it wont be hard... Just add the $_POST[fieldname] inplace of the info...
Originally posted by ethereality
And for the last question..
A sample of this would be a user submitting text into a textbox, say something labled "description", and it would submit everything that the user typed into "description.php" at the top. I say the top because everything is defined in variables, and the main coding is at the bottom. I assume you know that variables have to be written above the code using the variable.
I am not sure im still getting it, but if you want to display information on top of the file from a post form, use the "echo $_POST[fieldname];"..
Peace,
ethereality 08-22-2005, 10:09 PM Thank you, I knew how to od the post function, I just wanted to to make sure I could.
For the second question:
Here's a basic file creator/editor:
<?
$filename = $_POST["filename"];
$theText = $_POST["theText"];
$theText = stripslashes($theText);
$data = fopen($filename, "a");
fwrite($data,$theText);
fclose($data);
echo "File created or updated";
?>
That would add $theText to the bottom of a file (if it exists).
What I want to do though is add $theText to the top of a file.
2detailed 08-23-2005, 10:02 AM http://us2.php.net/manual/en/function.fseek.php or open it with r+.
azizny 08-23-2005, 10:03 AM Originally posted by ethereality
Thank you, I knew how to od the post function, I just wanted to to make sure I could.
For the second question:
Here's a basic file creator/editor:
<?
$filename = $_POST["filename"];
$theText = $_POST["theText"];
$theText = stripslashes($theText);
$data = fopen($filename, "a");
fwrite($data,$theText);
fclose($data);
echo "File created or updated";
?>
That would add $theText to the bottom of a file (if it exists).
What I want to do though is add $theText to the top of a file.
There is no direct way, but this would do:
$filename = $_POST["filename"];
$theText = $_POST["theText"];
$theText = stripslashes($theText);
$file_info = fclose(fread(fopen($filename,'r'),filesize($filename)));
$data = fopen($filename, "w");
fwrite($data,$file_info."\n".$theText); //\n would make a new line
fclose($data);
echo "File created or updated";
If the first long line does not work, shorten it :D
EDIT: I would go with 2detailed soultion...
Peace,
|