By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

Help-news updater

P: n/a
I will that with form send data to database, and then that data read from
database.
Example:
Name: Kole
Subject: Help
Text: I need help, please help me!
Than i press send and this data go to my database. And then I need read this
data on my page that newest data go up(first)!
Thank you all!

--
..:: KoLe ::.
izbriči "MAKNI" u mailu
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> I will that with form send data to database, and then that data read from
database.
Example:
Name: Kole
Subject: Help
Text: I need help, please help me!
Than i press send and this data go to my database. And then I need read this data on my page that newest data go up(first)!
Thank you all!


I think that first you should dig php manual in mysqlfunctions and some
mysql guide. Although you can do this kind of simple thing without database
too, using simple text files. But with database it is something like this
but I DONT HAVE TIME to try and debug this!

- first you need to create database with sql query :
create database messages ( msg_id int(10) auto_increment, name char 100,
subject char(150), text text);
- then you need to create script that adds messages to database:
- $conn = mysql_connect(........) or die("oh no");
- $name = mysql_real_escape_str($_POST['name']);
- $subject = mysql_real_escape_str($_POST['subject']);
- $text = mysql_real_escape_str($_POST['text']);
- $query = mysql_query("INSERT INTO messages VALUES
('$name','$subject','$text')") or die("oh no");
- then you need to create script that reads messages from database:
- $query = mysql_query("SELECT * FROM messages") or die("oh no");
- while($row = mysql_fetch_object($query)) { echo $row->name etc etc...}


Jul 17 '05 #2

P: n/a
OKAY, litte more correct version (not 100%)

- first you need to create database with sql query :
create database messages ( msg_id int(10) auto_increment, name char 100,
subject char(150), text text, time timestamp);
- then you need to create script that adds messages to database:
- $conn = mysql_connect(........) or die("oh no");
- $name = mysql_real_escape_str($_POST['name']);
- $subject = mysql_real_escape_str($_POST['subject']);
- $text = mysql_real_escape_str($_POST['text']);
- $query = mysql_query("INSERT INTO messages VALUES
(NULL, '$name','$subject','$text')") or die("oh no");
- then you need to create script that reads messages from database:
- $query = mysql_query("SELECT * FROM messages ORDER BY time desc") or
die("oh no");
- while($row = mysql_fetch_object($query)) { echo $row->name etc etc...}
Jul 17 '05 #3

P: n/a
Even more correct version (not 100% :-)

- first you need to create database 'msg_dbase' with sql query :
CREATE DATABASE msg_dbase;

- THEN you need to create table 'messages' with sql query:
CREATE TABLE messages ( msg_id int(10) auto_increment, name char 100,
subject char(150), text text, time timestamp);

- then you need to create script that adds messages to database:

$conn = mysql_connect($host, $username, $password) or die("oh no");
mysql_select_db('msg_dbase', $conn) or die("oh no");
$name = mysql_real_escape_string($_POST['name']);
$subject = mysql_real_escape_string($_POST['subject']);
$text = mysql_real_escape_string($_POST['text']);
$query = mysql_query("INSERT INTO messages VALUES
(NULL, '$name','$subject','$text')") or die("oh no");

- then you need to create script that reads messages from database:

$conn = mysql_connect($host, $username, $password) or die("oh no");
mysql_select_db('msg_dbase', $conn) or die("oh no");
$query = mysql_query("SELECT * FROM messages ORDER BY time desc") or
die("oh no");
while($row = mysql_fetch_object($query))
{
echo "<h2>".html_special_chars($row->subject)."</h2>";
echo "<h3>Written by ".html_special_chars($row->name)."</h3>";
echo "<p>".html_special_chars($row->text)."</p>";
}

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.