Kód: Vybrať všetko
<?php
@include('./config.php');// load config data
// connect and set DB
@mysql_connect(DB_SERVER, DB_LOGIN, DB_PASS) or die("Cannot connect to MySQL.");
@mysql_select_db(DB_NAME) or die("Cannot connect to database.");
mysql_query("SET NAMES 'UTF8'");
// connect and set DB
//============================= create table ==========================
mysql_query
("
CREATE TABLE IF NOT EXISTS data
(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) DEFAULT '' NOT NULL,
email VARCHAR(255) DEFAULT '' NOT NULL,
note VARCHAR(255) DEFAULT '' NOT NULL
)
COLLATE utf8_general_ci;
");
//============================= create table ==========================
// replace HTML chars
function textCheck($textCheck)
{
$textCheck = htmlspecialchars($textCheck, ENT_QUOTES);
$textCheck = preg_replace('/\r/', '', $textCheck);
if ($line) $textCheck = preg_replace('/\n\n/', '\n', $textCheck);
$textCheck = trim($textCheck);// remove spaces at the end and begining
return $textCheck;
}
// replace HTML chars
$name = textCheck($_POST['name']);
$email = textCheck($_POST['email']);
$note = textCheck($_POST['note']);
$warning = '';
// write to DB
if ($name != '' && $email != '' && $note != '')
{
mysql_query('INSERT INTO data (name, email, note) VALUES("' . $name . '", "' . $email . '", "' . $note . '");');
$warning = 'Saved.';
unset($name, $email, $note);// remove variables
}
elseif (isset($_POST['save'])) $warning = 'Please insert value to all fields.';
// write to DB
echo "<?xml version="1.0" encoding="UTF-8"?>\n";
?>vid
http://www.rovla.skmalacky.sk/write.php