Jump to content
php.lv forumi

Delete post


Gacha

Recommended Posts

Nu te ir news.php

<?  include_once("../protected/mysql_config.php");
$tablename = "news";


//izvadu informaciju no DB
if (mysql_select_db ($dbname)) { 
        $result = mysql_query ("Select * from $tablename order by id desc");
  if (mysql_affected_rows() != 0) { 
        while ($row = mysql_fetch_array ($result)) {
    echo "<table width='300' border='1' cellpadding='0' cellspacing='0' bordercolor='#FFFFFF'>
                <tr>
                <td bgcolor='#003366'>
                <div align='center'><font color='#CCCCCC' size='-1' face='Geneva, Arial, Helvetica, sans-serif'><strong>".$row["tema"]."</strong></font></div></td>
                </tr>
                <tr>
                <td height='71' valign='top' bgcolor='#CCCCCC'>".$row["texts"]."</td>
                </tr>
                <tr>
                <td align='right' bgcolor='#003366'><font color='#CCCCCC' size='-1' face='Geneva, Arial, Helvetica, sans-serif'>".$row["datums"]."</font></td>
                </tr>
                </table>
    <form name='delete' method='post' action='delete.php'>
<input name='' type='hidden' value=".$row["id"].">
<input type='submit' name='id' value='Delete'>
<form/>
    "; }}}
    else echo "Neizdevaas";
    mysql_close();
	 

?>

Nu kad tas paraadaas tad zem katra postinja paraadaas submit podzinja, kura suuta attieciiga posta ID uz lapu delete.php

<?php
include("../protected/mysql_config.php");
$link = mysql_connect($hostname,$dbuser,$dbpass);
mysql_select_db("$dbname");
mysql_query("delete from news where id = ".$HTTP_POST_VARS['id']."");



mysql_close();
?>

Cik sapratu tad no news.php vinjsh visu smuki aisuuta, bet problema varetu buut delete.php

Nu un veel dereetu taas abas lapinjas nedaudz izpushkjot, varbuut var kaads kaut ko paliidzeet?

 

PS. Problema ir taa ka nospiezh pogu delete tad aiziet uz lapu delete.php bet nekas nenotiek, pat errorus nemet araa.

Link to comment
Share on other sites

Es uz taisiju shitaa: news.php

<?  include_once("../protected/mysql_config.php");
$tablename = "news";


//izvadu informaciju no DB
if (mysql_select_db ($dbname)) { 
        $result = mysql_query ("Select * from $tablename order by id desc");
  if (mysql_affected_rows() != 0) { 
        while ($row = mysql_fetch_array ($result)) {
    echo "<table width='300' border='1' cellpadding='0' cellspacing='0' bordercolor='#FFFFFF'>
                <tr>
                <td bgcolor='#003366'>
                <div align='center'><font color='#CCCCCC' size='-1' face='Geneva, Arial, Helvetica, sans-serif'><strong>".$row["tema"]."</strong></font></div></td>
                </tr>
                <tr>
                <td height='71' valign='top' bgcolor='#CCCCCC'>".$row["texts"]."</td>
                </tr>
                <tr>
                <td align='right' bgcolor='#003366'><font color='#CCCCCC' size='-1' face='Geneva, Arial, Helvetica, sans-serif'>".$row["datums"]."</font></td>
                </tr>
                </table>
    <form name='delete' method='post' action='delete.php'>
<input name='id' type='hidden' value='".$row["id"]."'>
<input type='submit' name='submit' value='Delete'>
<form/>
    "; }}}
    else echo "Neizdevaas";
    mysql_close();
	 

?>

un delete.php ir shitaads

<?php
include("../protected/mysql_config.php");
$tablename = "news";
$link = mysql_connect($hostname,$dbuser,$dbpass);
mysql_select_db("$dbname");
//dzeshu informaciju DB
$del_str = "DELETE from $tablename where id='".$HTTP_POST_VARS['id']."'"; 
if (mysql_query ($del_str, $link)) 
        {  echo "Posts dzests!.</p>"; 
        }
  mysql_close();
?>

 

Nu tagad vinjsh dzesh ierakstus, bet ir taada problema, ka vinjsh dzeesh ne to pie kura pogu nospiesta bet vienkaarshshi dzeesh saakot ar pirmo postu.

 

Kaut kas nav kartiibaa ar to news.php cik saprotu tad vinjsh aizsuuta ID=1 nevis ID=.$row["id"]. kapeec taa?

Link to comment
Share on other sites

<input name='' type='hidden' value=".$row["id"].">
<input type='submit' name='id' value='Delete'

Pameigini nomainit to ID, kas ir pie submit uz kadu citu nosaukumu!

Tad kad vins tev ir izvadijis to PHP HTML formata, tad paskaties source vai vins vispar liek tos dazadus ID.

Link to comment
Share on other sites

Es panjemo un delete.php lapaa prosta uztaisiju

echo ("Posts ".$HTTP_POST_VARS['id']." ir dzests");

Un vinjsh man uzradija peedeejaa posta nummuru.

 

Tad tomeer vaina ir tai news.php

 

Nomainiju to id , bet nav nekaada atshkjiriba. Tur ir kaut kaada cita problema. <_<

Link to comment
Share on other sites

Vai paskatijies source, kad tiek izvadita ta lapa! Tad tu redzetu, kas taja ID tiek rakstits! Un vai ID nomainiji pie submita. Tev tur stav submit un name='id', nomaini to uz citu, Vienkarsi tev ta vertiba ID tiek pieskirta tam te nevis tabulas id!

Link to comment
Share on other sites

varbuut tapeec,ka tu html iisti nekorekti esi uzrakstiiji:

 

<form name='delete' method='post' action='delete.php'>

<input name='id' type='hidden' value='".$row["id"]."'>

<input type='submit' name='submit' value='Delete'>

<form/>

 

 

baigaas ir jaabuut </form>

 

tagad tev visticamaak ir viena forma ar daudz id laucinjiem un tad vinjsh panjem peedeejo.

Link to comment
Share on other sites

nu man news.php ir shitaa:

<form name='delete' method='post' action='delete.php'>
<input name='id' type='hidden' value='".$row["id"]."'>
<input type='submit' name='submit' value='Delete'>
<form/>

 

Nu forma tur aiztaisaas. Veel es noliku pie katra posta lai vinjsh uzrada ID un tur vinjsh to arii uzraada pareizi, bet kad posto to uz delete.php tad tas sanjem pirmaa posta ID

 

delete.php

<?php
include("../protected/mysql_config.php");
$tablename = "news";
$link = mysql_connect($hostname,$dbuser,$dbpass);
mysql_select_db("$dbname");
//dzeshu informaciju DB
$del_str = "DELETE from $tablename where id='".$HTTP_POST_VARS['id']."'"; 
if (mysql_query ($del_str, $link)){echo "Posts ".$HTTP_POST_VARS['id']." ir dzests. ";}
 else{
          echo "Neizdevaas dzest";}

 
  mysql_close();
?>
<a href="news.php">Atpakall</a>

 

Klluda ir kaut kur news.php ar to delete podzinju.

 

Itkaa ir veel viens variants ar kaut kaut kaadu if action.... Taa ir?

Link to comment
Share on other sites

Nu tev to kodu ir mazliet jaizmaina pameigi kaut ko tadu,

Arial, Helvetica, sans-serif'><strong>".$row["tema"]."</strong></font></div></td>
               </tr>
               <tr>
               <td height='71' valign='top' bgcolor='#CCCCCC'>".$row["texts"]."
               <a href=\"delete.php?stastaid=".$row["id"]."\"> Dzēst</a>
</td>
               </tr>
               <tr>
               <td align='right' bgcolor='#003366'><font color='#CCCCCC' size='-1' face='Geneva, Arial, Helvetica, sans-serif'>".$row["datums"]."</font></td>
               </tr>
               </table>

 

Un tad faila delete

 

 

<?php
include("../protected/mysql_config.php");
$tablename = "news";
$link = mysql_connect($hostname,$dbuser,$dbpass);
mysql_select_db("$dbname");
//dzeshu informaciju DB
$del_str = "DELETE from $tablename where id=$stastaid "; 
if (mysql_query ($del_str, $link)) 
       {  echo "Posts dzests!.</p>"; 
       }
 mysql_close();
?>

 

To submitu un viu formu rubija araa!

Neesu parliecinats par so lietu, varbut kaut kur bus japielabo, vai kads komatins, vai semikolins ir nozudis, nez kapec man ta gadas loti biezi! :D

Link to comment
Share on other sites

Man delete.php saka ka

Notice: Undefined variable: stastaid in d:\usr\www\db\delete.php on line 9

 

php.delete.php

<?php
include("../protected/mysql_config.php");
$tablename = "news";
$link = mysql_connect($hostname,$dbuser,$dbpass);
mysql_select_db("$dbname");
//dzeshu informaciju DB
$del_str = "DELETE from $tablename where id=$stastaid "; 
if (mysql_query ($del_str, $link)){echo "Posts ir dzests. ";}
 else{
          echo "Neizdevaas dzest";}

 
  mysql_close();
?>
<a href="news.php">Atpakall</a>

 

Saprotu to ka vinjsh nesaprot to $stastaid ka var to nodefineet?

 

 

un te ir news.php bez taas submit pogas. (рпр tagad es ieraudziju to klluudu :D )

<html>
<head>
<title>NEWS</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1257">
</head>

<body>
<a href="post_news.php" target="_self">Ievietot postu</a>
<?  include_once("../protected/mysql_config.php");
$tablename = "news";


//izvadu informaciju no DB
if (mysql_select_db ($dbname)) { 
        $result = mysql_query ("Select * from $tablename order by id desc");
  if (mysql_affected_rows() != 0) { 
        while ($row = mysql_fetch_array ($result)) {
    echo "<table width='300' border='1' cellpadding='0' cellspacing='0' bordercolor='#FFFFFF'>
                <tr>
                <td bgcolor='#003366'>
                <div align='center'><font color='#CCCCCC' size='-1' face='Geneva, Arial, Helvetica, sans-serif'><strong>".$row["tema"]."</strong></font></div></td>
                </tr>
                <tr>
                <td height='71' valign='top' bgcolor='#CCCCCC'>".$row["texts"]."</td>
                </tr>
                <tr>
                <td align='right' bgcolor='#003366'><font color='#CCCCCC' size='-1' face='Geneva, Arial, Helvetica, sans-serif'>".$row["datums"]."</font></td>
                </tr>
                </table>
    <a href=\"delete.php?stastaid=".$row["id"]."\"> Dzēst</a>

    "; }}}
    else echo "Neizdevaas";
    mysql_close();
	 

?>
</body>
</html>

 

PS. Es daru taa, ja gribu html kodu ielikt php tad uztaisu to uz html ielieku php un visur kur ir " partaisu par ' un lieta darita. Ja to drukaa uz php tad taksh iisti nevar zinaat kaa tas izskatiisies!

Link to comment
Share on other sites

$stastaid neatrod tāpēc, ka, droši vien, uz servera ir "register_globals off", tādēļ tev jāatsaucās, kā uz $_GET['stastaid']

 

P.S. Ja kaut ko izlabo savā n-rindu kodā, tad, lūdzu, arī izcel šīs izmaiņas kaut kādā veidā, ja nevēlies, lai tevi uzskata par nepieklājīgu.

Edited by Aleksejs
Link to comment
Share on other sites

OOO!!! :D :D :D Ir. Lai tiktu pie taadas lietas, ka var iepostot postus un tad tos izdzees es pa internetu un forumiem mekleejos dienu no dienas jau meenesi un tagad tas ir.

 

Lielas paldies!!!

 

Tik varetu man pateikt, ko man veel vajadzeetu tur pielikt, lai buutu droshaak pareizaak?

 

Piemeeram add.php vajadzeetu kaadus filtrus vai arii veel kaut ko ko juus tur parasti sarakstaat vesalaam kaudzeem :D add.php

<? include("../protected/mysql_config.php");
   $tablename = "news";
$link = mysql_connect($hostname,$dbuser,$dbpass);
mysql_select_db("$dbname");
//pievienoju informaciju DB
$ins_str = "Insert into $tablename set tema='".$HTTP_POST_VARS['tema']."', texts='".$HTTP_POST_VARS['texts']."', id='".$HTTP_POST_VARS['id']."', datums='".date("Y-m-d H:i:s")."'"; 
if (mysql_query ($ins_str, $link)) 
        {  echo "Posts ir veiksmigs!.</p>"; 
        }
  mysql_close();


?>
<a href="post_news.php" target="_self">Ievietot jaunu?</a>

Link to comment
Share on other sites

×
×
  • Create New...