Jump to content
php.lv forumi

paskaidrojiet luudzu


mad182

Recommended Posts

nu taa, ar mysql iepazinos vakar, taapeec man daudz kas nav skaidrs, varbuut kaads var paliidzeet. Taatad meegjinaaju izveidot vienkaarshu fisku - formu kuraa ievada textu, saglabaa datubaazee un peec tam izvada ienkaarshi. protams man nekas nedarbojas, varbuut kaads vareetu uzrakstiit skriptu ar kuru viss darbojas. megjinaaju shitaa:

 

<?php

mysql_connect("localhost","root","") or die("Shit happen!");

print("
<form action='meegjinos.php' method='post'>
<input type='text' name='txt'>
<input type='submit' name='sbmt' value='Lielaa poga'>
</form>
");
if($_POST['sbmt']){
if(empty($txt))print("Lauks ir tuk!");
else{
mysql_db_query(test, "INSERT INTO nesanaak ('id', 'vaards') VALUES('', '$txt')");
}
}

$rezultats = @mysql_db_query(test, "SELECT ('vaards') FROM nesanaak");

print("<br/>$rezultats");

?>

Link to comment
Share on other sites

sac ar kaut ko vienkarsaku par forumu - thipa viesu gramatu taisi

 

vispirms vajadzes db uztaisit tabulu, piemeram shitadu

CREATE TABLE ieraksts (

id int(11) NOT NULL auto_increment,

datums datetime NOT NULL default '0000-00-00 00:00:00',

nicks varchar(32) collate utf8_latvian_ci NOT NULL default '',

zinja text collate utf8_latvian_ci NOT NULL,

PRIMARY KEY (id)

)

 

ielikt ierakstu db varesi ar sql

insert into ieraksts(datums, nicks, zinja) values (now(), "niks", "es te biju!")

 

nolasit ierakstus un sakartot pec datuma atkal ar shitadu sql

select datums, nicks, zinja from ieraksts order by datums desc

 

ja taisies kauch cik nopietni piekerties php/mysql programesanai, tad noteikti ka vajadzes izstudet shito - http://lv.php.net/manual/en/ref.mysql.php iesakumaa pievers uzmanibu shitaam f-jaam - mysql_connect, mysql_select_db, mysql_query,mysql_fetch_row, mysql_error.

Link to comment
Share on other sites

<?
$dbLink = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('db_name');

if (isset($_POST['enter'])) {
 empty($_POST['vards']) ? $vards = '- - -' : $vards = $_POST['vards'];

 $query = "INSERT INTO table (id,name) VALUES (NULL,'$vards')";
 mysql_query($query);
}
?>
<form method="post" action="" enctype="multipart/form-data">
 <p>
 Vards: <input type="text" name="vards" maxlength="30" size="23" /><br />
 <input type="submit" name="enter" value="OK" /><br />
 </p>
</form>
<?
$query = "SELECT * FROM table";
$result = mysql_query($query);
$rows = mysql_fetch_array($result);
var_dump($rows);
?>

 

Uz ātru roku uzmeistaroju.

mysql_db_query nomaini pret mysql_query

Link to comment
Share on other sites

×
×
  • Create New...