linkedin facebook linkedin facebook nod32

Saytda php yordamida qanday qilib sharhlar(Izoh) qoldirish

Muallif: Mengliyev Sh.

Qo`shilgan sana: 2015-09-07

Saytda php yordamida qanday qilib sharhlar(Izoh) qoldirish

Php va MySql lardan qanday foydalanish va sharhlar(izohlar) qoldirish mumkinligini yoritib beraman.
Biz php da saytlarga sharh qoldirish kodlarini qanday tuzish mumkinliginihal qilamiz.
Qadam 1. PhpMyadmin da ma’lumotlar bazasida jadvol tuzamiz uni Sql bo`limiga joylashtiramiz Sql kodi quyidagicha.

CREATE TABLE `xat` (
`id` int( 10 ) NOT NULL AUTO_INCREMENT ,
`author` varchar( 255 ) NOT NULL default '',
`contact` varchar( 255 ) NOT NULL default '',
`text` text NOT NULL default '',
KEY `id` ( `id` )
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=205 ;


Bazani  joylashtirgan bo`lsangiz.

Qadam 2. Jadvalni tuzib olgandan keyin. Endi formalarni qayta ishlaymiz unig uchun maktub_yuborish.php faylini quyidagicha kodlaymiz  <html> tegi yuqori qismiga quyidagi php kodni joylashtiramiz.
<?
$db = mysql_connect ("localhost","root","");
mysql_select_db("xat",$db);
if (isset($_POST['author']))      {$author = $_POST['author']; if ($author == '') {unset($author);}}
if (isset($_POST['contact']))      {$contact = $_POST['contact']; if ($contact == '') {unset($contact);}}
if (isset($_POST['text']))        {$text = $_POST['text']; if ($text == '') {unset($text);}}
$dat = date("Y-m-j");
?>

Qadam 3. Html formaning har bir betiga joylashtiramiz. Siz Izoh qoldiruvchi bo`lim qo`shmoq u quyidagicha yoziladi.
<form method="post" name="contact" action="Maktub_yuborish.php">
<p><label>Ismingiz: </label><input name="author" type="text" size="30" maxlength="30"></p>
<p><label>Mavzu: </label><input name="contact" type="text" size="30" maxlength="30"></p>
<p><label>Fikrigizni qoldiring:<br> <textarea name="text" cols="50" rows="4"></textarea></label></p>
<br>
<p><input name="sub_com" type="submit" value="Yuborish"></p>
<p><input type="reset" onclick=window.Reset() value="Tozalash" name="reset"  /></p>
</form>
<?php
if (isset($author) && isset($contact) && isset($text))
{

function post_data_is_valid ()
{

if (isset($_POST['$author'])) {
$author = trim($_POST['$author']);
if (!preg_match('/^.{3,128}$/', $author)) {
return '<script>alert(\'izoh qoldiruvchining FISH"\')</script>';
}
} else
return false;


if (isset($_POST['$contact'])) {
$contact = trim($_POST['$contact']);
if (!preg_match('/^.{3,30}$/', $contact)) {
return '<script>alert(\'e-mailni yoki mavzu qo`shish ')</script>';
}
} else
return false;

        if (isset($_POST['$text'])) {
$text = trim($_POST['$text']);
if (!preg_match('/^.{3,128}$/', $text)) {
return '<script>alert(\'Izoh yo sharhlar xatlar qoldirish\')</script>';
}
} else
return false;

          return  array (

'$author' => $author,
'$contact' => $contact,
'$text' => $text

);
}

$author = stripslashes($author); $author = htmlspecialchars($author);   
$contact = stripslashes($contact);$contact = htmlspecialchars($contact);
$text = stripslashes($text); $text = htmlspecialchars($text);   

/* Agar qo`shilgan mavzu yoki izohlar tekshirish bo`limi*/
$result = mysql_query ("INSERT INTO xat (author,contact,text,date) VALUES ('$author','$contact','$text','$dat')");
$author=0; $contact=0; $text=0; $dat=0;
if ($result == 'true') {echo "<h> Habringiz qabul qilindi rahmat </h>";}
else {echo "<h>Habar kiritishda xatolik bor qaytadan urinib ko`ring?  </h>";}
}                
else

{
echo "<h>Habaringiz qabul qilinmadi qaytadan urinib ko`ring? </h>";
}
?>

<?
$result4 = mysql_query("SELECT DISTINCT left(date,10) AS month FROM xat ORDER BY month DESC",$db);
$myrow4 = mysql_fetch_array($result4);
$dat=$myrow4['month'];
$result41 = mysql_query("SELECT * FROM xat WHERE  date='$dat' or date>'$dat' ORDER BY date DESC,id DESC LIMIT 0, 5",$db);// 5 ta izohni o`z ichiga oladi
$myrow41 = mysql_fetch_array($result41);
do {printf ("<div id='temp_foot2' class='zzzzz5'>
Ismingiz:%s<br>Mavzu:%s <br>date:%s
<br>Fikrigizni qoldiring:%s
</div><br>",$myrow41["author"],$myrow41["contact"],$myrow41["date"], $myrow41["text"] );
}
while ($myrow41 = mysql_fetch_array($result41));

?>

2611 marta o`qildi.

Parol:
Eslab qolish.


Ro`yhatdan o`tish


Рейтинг@Mail.ru
Рейтинг@Mail.ru

Besucherzahler
счетчик посещений