Jump to content
php.lv forumi

A litle Problem


realfun

Recommended Posts

Es esmu izveidojis shadu scriptu

 <?php
//Pieslēgšanās datubāzei

$db_host = 'localhost';
$db_user = 'root';
$db_password = 'real112';
$db_name = 'sistema';

$connection = @mysql_connect($db_host, $db_user, $db_password) or die(mysql_error());
mysql_select_db($db_name, $connection);
mysql_query("SET NAMES utf8");
//Ievietošana datubazē
$sql="INSERT INTO viesene (vards, lapa, zinja)
VALUES
('$_POST[vards]','$_POST[lapa]','$_POST[zinja]')";

if (!mysql_query($sql,$connection))

	echo "<span class='ok'>Pievienots</span><br />";
else
{
	echo "<span class='error'>Kāds lauks palika tukšs!</span><br />";
}

//Izvilkšana
$result = mysql_query("SELECT * FROM viesene");

while($row = mysql_fetch_array($result))
 {
 echo "<br>";
 echo "<br>" . $row['vards'] . "</td>";
 echo "<br>" . $row['lapa'] . "</td>";
 echo "<br>" . $row['zinja'] . "</td>";
 echo "</br>";
 }

mysql_close($connection)
?>



<form method="post" action="">
Vards: <br />
<input type="text" name="vards"><br />
majaslapa: <br />
<input type="text" name="lapa"><br />
Vestule: <br />
<textarea name="zinja" cols="60" rows="10"></textarea><br />
<input type="submit" value="pievienot">
</form> 

itka viss ok vinjsh ievada bazee un izvada bet ka lapu refresho vinjsh atkal izvada to pas un ta visu laiku

 

CREATE TABLE `sistema`.`viesene` (
`id` INT NOT NULL AUTO_INCREMENT ,
`vards` VARCHAR( 255 ) NOT NULL ,
`lapa` VARCHAR( 255 ) NOT NULL ,
`zinja` TEXT NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = InnoDB;

 

reku msql kods ja gadijuma vesapratat ludzu palidzat ja varat izlabojat ja ne ludzu pasakat kapec ta ir!

 

nevarētu but vaina ar to action?

Edited by realfun
Link to comment
Share on other sites

lai pēc refreša pa jaunam netiktu sūtīti dati, pēc inserta vajag uztaisīt redirect uz esošo lapu (vai uz "vieseni", ja tā un pievienošana ir dažādos failos vai adresēs)

header('Location: ' . $_SERVER['REQUEST_URI']);

Edited by 2easy
Link to comment
Share on other sites

Un vēlams URL vēl klāt piekabināt randskaitli, savādāk ej nu sazini vai ar kešoto nesaber pilnu bāzi kā no ložmetēja:)

Un vēl tai kodā neredzu ka čekotu vispār ir vai nav post dati un tad jau attiecīgi raksta bāzē vai tikai izvada tekstus un formu.

Vēl ieteikums likt bāzē arī ieraksta laiku, var noderēt.

Edited by mounkuls
Link to comment
Share on other sites

droši vien bezgalīgais redirect ;)

ieliec tajā formā darbību

<input type="hidden" name="action" value="pievienot" />

un pievienošanu veic tikai tad, kad atnāk forma ar attiecīgo darbību

if ($_POST['action'] == 'pievienot') {
   ...  // insert in db

   un beigās redirect
}

 

droši vien kodē savu pirmo formu, ja? ;)

Edited by 2easy
Link to comment
Share on other sites

aa un jaa man vinjš man met tagad erroru

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\mans\index.php:23) in C:\xampp\htdocs\mans\index.php on line 40

 

un tapat visu laiku ar refreshu met bazee iekšā un velk arā!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...