Difference between revisions of "Упражнениe 9. XAMPP"
From Ilianko
Line 52: | Line 52: | ||
<html> | <html> | ||
− | <head> | + | <head> |
− | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | + | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
− | <title>Untitled Document</title> | + | <title>Untitled Document</title> |
− | </head> | + | </head> |
− | <body> | + | <body> |
− | <form action="" method="post"> | + | <form action="" method="post"> |
− | <table> | + | <table> |
− | <tr> | + | <tr> |
− | <td> | + | <td>nomer</td> |
− | <td><input type="text" name="fakN" value="" maxlength="9" /></td> | + | <td><input type="text" name="fakN" value="" maxlength="9" /></td> |
− | </tr> | + | </tr> |
− | <tr> | + | <tr> |
− | <td>ime</td> | + | <td>ime</td> |
− | <td><input type="text" name="name" value="" maxlength="100" /></td> | + | <td><input type="text" name="name" value="" maxlength="100" /></td> |
− | </tr> | + | </tr> |
− | <tr> | + | <tr> |
− | <td> | + | <td>familia</td> |
− | <td><input type="text" name="surname" value="" maxlength="100" /></td> | + | <td><input type="text" name="surname" value="" maxlength="100" /></td> |
− | </tr> | + | </tr> |
− | <tr> | + | <tr> |
− | <td>komentar</td> | + | <td>komentar</td> |
− | <td><textarea rows="3" cols="20" name="comment"></textarea></td> | + | <td><textarea rows="3" cols="20" name="comment"></textarea></td> |
− | </tr> | + | </tr> |
− | <tr> | + | <tr> |
− | <td colspan="2"><input name="submit" type="submit" value="Submit" /></td> | + | <td colspan="2"><input name="submit" type="submit" value="Submit" /></td> |
− | </tr> | + | </tr> |
− | </table> | + | </table> |
− | </form> | + | </form> |
− | + | <?php print $comments ?> | |
− | <?php print $comments ?> | + | </body> |
− | </body> | ||
</html> | </html> | ||
Revision as of 09:27, 22 March 2011
Задача
Използвайте phpMyAdmin за да създадете база данни с две таблици
1. Таблица students
fakN : name : surname : email
2. Таблица comments
id : fakN : comments : time
Полето time да е от тип TIMESTAMP
Създайте форма за качване на коментари
fakN, name, surname, comment Ако вече има писани коментари от този потребител, се добавя само коментара към базата дании.
Изполвайте
<?php
//svyrzvane kym MySQL server
$sql = mysql_connect('localhost', //adres
'root', // potrebitel
'123'); // parola
// Izbor na DB
mysql_select_db('tesss', // ime baza danni
$sql); // pointer kym bazata danni
if( isset($_POST['submit']))
{
$query = "SELECT * FROM students WHERE fakN = $_POST[fakN]"; // zaqvka kym DB server
$result = mysql_query($query); // Izprashtane na zaqvkata
if(mysql_num_rows($result))
{
$query = "INSERT INTO comments (`fakN`, `comments`) VALUES ( $_POST[fakN], '$_POST[comment]')";
$result = mysql_query($query);
}
else
{
$query = "INSERT INTO students (`fakN`, `name`, `surname`) VALUES ( $_POST[fakN], '$_POST[name]', '$_POST[surname]')";
$result = mysql_query($query);
$query = "INSERT INTO comments (`fakN`, `comments`) VALUES ( $_POST[fakN], '$_POST[comment]')";
$result = mysql_query($query);
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post">
<table>
<tr>
<td>nomer</td>
<td><input type="text" name="fakN" value="" maxlength="9" /></td>
</tr>
<tr>
<td>ime</td>
<td><input type="text" name="name" value="" maxlength="100" /></td>
</tr>
<tr>
<td>familia</td>
<td><input type="text" name="surname" value="" maxlength="100" /></td>
</tr>
<tr>
<td>komentar</td>
<td><textarea rows="3" cols="20" name="comment"></textarea></td>
</tr>
<tr>
<td colspan="2"><input name="submit" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php print $comments ?>
</body>
</html>