Dopiero zaczynam PHP, zacząłem od tego tutoriala:
http://www.phazm.com/notes/easy-as-pie/eas...with-databases/
Wszystko ładnie chodzi, tylko, że jak dodaje coś z polskimi znakami to mi wychodzą krzaczki zamiast polskich znaków.
Kod
<?php
$user="username";
$password="password";
$database="database";
$connection=mysql_connect('localhost',$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
if ($_REQUEST['quote'] != "") {
if($_REQUEST['author'] != "") {
$author = $_REQUEST['author'];
} else {
$author = "Anonymous";
}
$quote = $_REQUEST['quote'];
$query="INSERT INTO `quotes` (`quote`,`author`) values ('" . mysql_real_escape_string($quote) . "','" . mysql_real_escape_string($author) . "')";
$result=mysql_query($query) or die(mysql_error());
echo("inserted quote: " . htmlentities($quote) . " by " . htmlentities($author) . " into database");
} else {
echo("<p>Please enter a quote and author</p>");
}
?>
<form action="" method="post">
<fieldset>
<legend>Add a Quote</legend>
<label for="quote">Quote:</label>
<input type="text" name="quote" id="quote" maxlength="255" />
<label for="author">Author:</label>
<input type="text" name="author" id="author" maxlength="40" />
<input type="submit" value="Add Quote" />
</fieldset>
</form>
mysql_close($connection);
?>
$user="username";
$password="password";
$database="database";
$connection=mysql_connect('localhost',$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
if ($_REQUEST['quote'] != "") {
if($_REQUEST['author'] != "") {
$author = $_REQUEST['author'];
} else {
$author = "Anonymous";
}
$quote = $_REQUEST['quote'];
$query="INSERT INTO `quotes` (`quote`,`author`) values ('" . mysql_real_escape_string($quote) . "','" . mysql_real_escape_string($author) . "')";
$result=mysql_query($query) or die(mysql_error());
echo("inserted quote: " . htmlentities($quote) . " by " . htmlentities($author) . " into database");
} else {
echo("<p>Please enter a quote and author</p>");
}
?>
<form action="" method="post">
<fieldset>
<legend>Add a Quote</legend>
<label for="quote">Quote:</label>
<input type="text" name="quote" id="quote" maxlength="255" />
<label for="author">Author:</label>
<input type="text" name="author" id="author" maxlength="40" />
<input type="submit" value="Add Quote" />
</fieldset>
</form>
mysql_close($connection);
?>
Co ciekawe, jak dodaje do bazy MySQL przez phpMyAdmin z polskimi znakami, to wszystko jest OK.