Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Creating a query with php.

duck you, I'm a dragon
Loyal Member
Joined
Apr 29, 2005
Messages
6,405
Reaction score
130
As I'm making an admin panel for my site, I want to make an option which allows me to edit the text on the home page. I already have a form and such ready, but I now want that when I click "go" it creates a query in mysql with the text I have enterd. And gets overwritten when I enter a new message. I have searched far and wide on google, but I can't find what I need. So if anyone knows how to do it, I would be very grateful if you post it.

Any help is much appreciated.
 
duck you, I'm a dragon
Loyal Member
Joined
Apr 29, 2005
Messages
6,405
Reaction score
130
Guess so, could you show it to me?
 
Joined
Aug 16, 2006
Messages
1,317
Reaction score
49
Sure no problem.

You need to have a form wrapped around all of the fields and submit button, make it go to.... submit-news.php.

News File:
PHP:
<link href="style.css" rel="stylesheet" type="text/css" />

<div align="center">Just a simple news system<strong> I</strong> made, cutenews was being a pain in the butt. 
  </p>
 Anyway, enjoy. </div>
</div>
<p> </p>
<form id="form1" name="form1" method="post" action="submit.php">
  <p align="center">News:</p>
  <p align="center">
    <label>
    <textarea name="textarea2" cols="100" rows="10" wrap="physical" class="breadcrumbs">Add your news here, it will automatticly be put into a php file, and then displayed on the homepage.
Aswell, this system, will also delete the previous news.</textarea>
    </label>
  </p>
  <p align="center"> </p>
  <p align="center">
    <label>
    <input name="submit" type="submit" class="none" id="submit" value="Submit News" />
    </label>
  </p>
</form>
<p align="center"> </p>
<p align="center">HTML CODES WORK WITH THIS NEW SYSTEM.

Submit-News.php File:
PHP:
<?php
if(isset($_POST['submit'])) {
$buffer .= "<?php\n";
$buffer .= "\$news = '".$_POST['textarea2']."';\n";
$buffer .= "echo \$news\n";
$buffer .= "?>\n";
$f = fopen('../news.php', 'w');
$fd = fwrite($f, $buffer);
$fe = fclose($f);
if($fd) {
echo('News Submitted<BR>
You can go back to the homepage by clicking <a href=../../index.php>here</a>');
} else {
echo('News submitition failed');
}
}
?>

Then just use
PHP:
<?php
include('news.php');
?>
and the news will show up on the main page.
Tell me if it works for you or not.
 
Divine Celestial
Loyal Member
Joined
Feb 11, 2006
Messages
890
Reaction score
0
Why not just utilize mysql for storing the new information? Much easier and more organized.
 
Divine Celestial
Loyal Member
Joined
Jul 7, 2004
Messages
853
Reaction score
5
But it will slow down the database alot if the news gets to big...
This entire forum uses MySQL. The performance isn't too bad. Besides, it's also used in many MMORPG servers, which host massiev amounts of data as well.
 
Newbie Spellweaver
Joined
Jan 2, 2007
Messages
13
Reaction score
0
Beside that, the script is far from being optimised. To have in your script $news = "whatever" and then echo $news that is just non sense.

If you want to do it the static way just save your file as *not* using PHP at all. This will save *a lot* generating time.

So instead of doing it this way:

PHP:
   <?php 
if(isset($_POST['submit'])) { 
$buffer .= "<?php\n"; 
$buffer .= "\$news = '".$_POST['textarea2']."';\n"; 
$buffer .= "echo \$news\n"; 
$buffer .= "?>\n"; 
$f = fopen('../news.php', 'w'); 
$fd = fwrite($f, $buffer); 
$fe = fclose($f); 
if($fd) { 
echo('News Submitted<BR> 
You can go back to the homepage by clicking <a href=../../index.php>here</a>'); 
} else { 
echo('News submitition failed'); 
} 
} 
?>
Why not doing it this way:

PHP:
   <?php 
if(isset($_POST['submit'])) { 
$buffer = $_POST['textarea2']; 
$f = fopen('../news.php', 'w'); 
$fd = fwrite($f, $buffer); 
$fe = fclose($f); 
if($fd) { 
echo('News Submitted<BR> 
You can go back to the homepage by clicking <a href=../../index.php>here</a>'); 
} else { 
echo('News submitition failed'); 
} 
} 
?>
 
Custom Title Activated
Loyal Member
Joined
Aug 8, 2004
Messages
3,892
Reaction score
20
Writing to file is ALWAYS slower then writing to a MySQL database. Don't make the mistake of writing the news in 1 field, add a new row for each newsitem.

As to database getting slower with many items: there are millions of posts on RZ, even if you add 5 news items a day it would take you over 800 years to achieve the same amount of posts, and RZ's database is still pretty fast (its the rest of it that isn't at times, but alas :wink:)
 
Back
Top