php localhost localhost dbuser root dbpass dbname Base if mysql_connec

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
$localhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'Base';
if(!mysql_connect($localhost,$dbuser,$dbpass)){
echo 'Ошибка соединения';
}
if(!mysql_select_db($dbname)){
echo 'Не найду БД';
}
//Обработчик
if(isset($_POST['submit'])){
$text = mysql_real_escape_string($_POST['text']);
if(!empty($text)){
mysql_query("INSERT INTO table SET
text = '".$text."'
);
}
}
echo '<form method="POST">
<input type="text" name="text"><br />
<input type="submit" name="submit" value="Добавить">
</form>';
$result = mysql_query("SELECT * FROM table");
while($res = mysql_fetch_assoc($result)){
echo $res['text'].'<br />';
}