kalyan
Продвинутый
Дата регистрации:
22.07.2012 17:02:42
Сообщений: 61
........................................
Warning: mysql_query() [function.mysql-query]: Access denied for user ''@'localhost' (using password: NO) in Z:\home\spec2\www\htdocs\mod4\gbook.php on line 69
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in Z:\home\spec2\www\htdocs\mod4\gbook.php on line 69
Access denied for user ''@'localhost' (using password: NO)
.........................................
<?php
define ('DB_HOST', 'localhost');
define ('DB_LOGIN', 'admin2');
define ('DB_PASS', '12345');
define ('DB_NAME', 'gbook');
mysql_connect(DB_HOST, DB_LOGIN, DB_PASS);
mysql_select_db(DB_NAME);
///////////////////////////////////////////
function clearData($data, $type ='s'){
switch($type){
case 's':
$data = trim(strip_tags($data));break;
case 'i':
$data = abs((int)$data);break;
}
return $data;
}
if(!empty($_POST['name']) && !empty($_POST['email'])){
$n = clearData($_POST['name']);
$e = clearData($_POST['email']);
$m = clearData($_POST['msg']);
$sql = "INSERT INTO msgs(name, email, msg) VALUES('$n','$e', '$m')";
mysql_query($sql) or die(mysql_error());
header("Location: gbook.php"
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
<head>
<title>Гостевая книга</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
</head>
<body>
<h1>Гостевая книга</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Ваше имя:<br />
<input type="text" name="name" /><br />
Ваш E-mail:<br />
<input type="text" name="email" /><br />
Сообщение:<br />
<textarea name="msg" cols="50" rows="5"></textarea><br />
<br />
<input type="submit" value="Добавить!" />
</form>
<?php
$sql = "SELECT * FROM `msgs` ORDER BY id DESC";
$users = mysql_query($sql) or die(mysql_error());
echo "<p>Всего записей: ".mysql_num_rows($users)."</p>";
mysql_close();
while($user = mysql_fetch_assoc($users)){
$msg = nl2br($user['msg']);
?>
<hr>
<p>
<h4> <a href="mailto:<?=$user['email']?>"><?=$user['name']?></a></h4>
<br />
<?=$msg?>
<p align="right">
<a href='gbook.php?del=<?=$user['id']?>'>Удалить</a>
</p>
</p>
<?php
}
if(isset($_GET['del'])){
$id = clearData($_GET['del'], 'i');
if($id > 0){
$sql = "DELETE FROM `msgs` WHERE id=$id";
mysql_query($sql) or die(mysql_error());
}
header("Location: gbook.php"
exit;
}
?>
</body>
</html>