mysql-ga qo'shib, o'sha sahifada o'chirib tashlash

Mening yozuvim bor

require('dbcon2.php');


  if(isset($_GET['submit1'])) { 
        if(isset($_POST['post_autor']) && isset($_POST['post_tresc'])) {

            mysqli_query($connect,"INSERT INTO news (tresc, autor) VALUES ('$_POST[post_tresc]', '$_POST[post_autor]')");

        }

  } elseif(isset($_GET['submit2'])) {

        if(isset($_POST['post_id_news2'])) {
            $usun = $_POST['post_id_news2'];

            mysqli_query($connect,"DELETE FROM news WHERE id_news = ".$usun."");
        }   else {
            echo 'Proba usunieca postu o pustym id.';
        }

    }

Men uni bitta sahifada o'chirib qo'yishdan oldin (hehe) o'qimoqchi edim, lekin variantni o'chirib tashlamoqchi bo'ldim va hech narsa qilolmadim.

HTML:


    <head>
        <meta charset="utf-8">

        
    </head>
    <body> 
        <div class="cztery">
            

PODGLĄD

 
            <table border="5"  bordercolor="#a64dff" align="center" style="max-width:20px;">
                <?php
                    $result = mysqli_query($connect,"SELECT autor,id_news FROM news GROUP BY id_news");
                    while($row = mysqli_fetch_array($result)) 
                    { 
                    echo '<tr><td>'.$row['id_news'].'</td><td>'.$row['autor'].'</td></tr>';
                    }
                ?>
            </table>
        </div>
        <div class="czteryipol">
            

EDYCJA

 
             <form action="kwadrat.php?go=czesc" method="post" id="usrform" align="center">

                

Autor
<input type="text" size="20" name="post_autor"/>

 


                

qilishdaj artykuł:

 
                


<input name="submit1" type="submit" value="OK"/>
</form> <form action="kwadrat.php?go=czesc" method="post" id="usrform" align="center">

Usuń artykuł

    
            

Numer artykułu
<input type="text" size="5" name="post_id_news2"/>

    
            <input name="submit2" value="OK" type="submit"/>
</form> </div> </body> </html>

Agar kimdir xatolarim qayerda ekanligini aytib bersa, men juda minnatqilishr bo'laman

nihoyat tahrir:

Yordamingiz uchun tashakkur, men shuni aniqladim:

buning o'rniga

($_GET['submit1']) 

qilish

($_POST['submit1'])
0
So'rovlarni parametrlashtiring.
qo'shib qo'ydi muallif User formerly known as chris85, manba
Iltimos, hozirgi ikkita javob sizni to'g'ri yo'nalishda ko'rsatmasa HTMLni ham joylashtiring ...
qo'shib qo'ydi muallif varlogtim, manba
O'ylaymanki, uning barcha masalalari
qo'shib qo'ydi muallif Dawid, manba

6 javoblar

Quyidagi ba'zi nosozliklarni keltirib chiqaradigan narsalar: 1. Ikkinchi yuborishni aslida # debug1 deb nomlang. 2. delete iborasi uchun MySQL xatolar # debug2 uchun keyingi tekshirish.

require('dbcon2.php');


if(isset($_GET['submit1'])) { 

    echo 'submit1: was called'; #debug1

    if(isset($_POST['post_autor']) && isset($_POST['post_tresc'])) {

        mysqli_query($connect,"INSERT INTO news (tresc, autor) VALUES ('$_POST[post_tresc]', '$_POST[post_autor]')");

    }
} 
elseif(isset($_GET['submit2'])) {

    echo 'submit2: was called'; #debug1

    if(isset($_POST['post_id_news2'])) {
        $usun = $_POST['post_id_news'];

        #debug2
        if(!mysqli_query($connect,"DELETE FROM news WHERE id_news = ".$usun."")) {
                echo 'MySQL error: ' . mysqli_error($connect);
        }
    } 
    else {
        echo 'Proba usunieca postu o pustym id.';
    }
}
0
qo'shib qo'ydi
Aslida, bu yo'qolgan jingalak brace emas, balki ... Xato nima degani?
qo'shib qo'ydi muallif varlogtim, manba
Kappa faylining oxirida xatolik yuz berdi
qo'shib qo'ydi muallif Dawid, manba
Men faqatgina "99-sonli satrda xato" borligini angladim, ammo bu mening oxirgi xatimdir, yordam uchun rahmat
qo'shib qo'ydi muallif Dawid, manba

Quyidagi ba'zi nosozliklarni keltirib chiqaradigan narsalar: 1. Ikkinchi yuborishni aslida # debug1 deb nomlang. 2. delete iborasi uchun MySQL xatolar # debug2 uchun keyingi tekshirish.

require('dbcon2.php');


if(isset($_GET['submit1'])) { 

    echo 'submit1: was called'; #debug1

    if(isset($_POST['post_autor']) && isset($_POST['post_tresc'])) {

        mysqli_query($connect,"INSERT INTO news (tresc, autor) VALUES ('$_POST[post_tresc]', '$_POST[post_autor]')");

    }
} 
elseif(isset($_GET['submit2'])) {

    echo 'submit2: was called'; #debug1

    if(isset($_POST['post_id_news2'])) {
        $usun = $_POST['post_id_news'];

        #debug2
        if(!mysqli_query($connect,"DELETE FROM news WHERE id_news = ".$usun."")) {
                echo 'MySQL error: ' . mysqli_error($connect);
        }
    } 
    else {
        echo 'Proba usunieca postu o pustym id.';
    }
}
0
qo'shib qo'ydi
Aslida, bu yo'qolgan jingalak brace emas, balki ... Xato nima degani?
qo'shib qo'ydi muallif varlogtim, manba
Kappa faylining oxirida xatolik yuz berdi
qo'shib qo'ydi muallif Dawid, manba
Men faqatgina "99-sonli satrda xato" borligini angladim, ammo bu mening oxirgi xatimdir, yordam uchun rahmat
qo'shib qo'ydi muallif Dawid, manba

if(isset($_POST['post_id_news2'])) { //<- Here is your culprit I think $usun = $_POST['post_id_news'];

Siz post_id_news2 (oxirida eslatma 2) parametrini tekshirasiz, so'ng post_id_news parametrini ishlatmoqchi bo'lsangiz.

Siz qaysi birini ishlatayotganingizni bilmayman, ammo sizning holatlaringizda ular bir xil bo'lishi kerak.

Also I suggest you read this: Escaping parameters for MySQL queries

0
qo'shib qo'ydi
shukur, lekin bu hech narsani o'zgartirmadi: p
qo'shib qo'ydi muallif Dawid, manba

if(isset($_POST['post_id_news2'])) { //<- Here is your culprit I think $usun = $_POST['post_id_news'];

Siz post_id_news2 (oxirida eslatma 2) parametrini tekshirasiz, so'ng post_id_news parametrini ishlatmoqchi bo'lsangiz.

Siz qaysi birini ishlatayotganingizni bilmayman, ammo sizning holatlaringizda ular bir xil bo'lishi kerak.

Also I suggest you read this: Escaping parameters for MySQL queries

0
qo'shib qo'ydi
shukur, lekin bu hech narsani o'zgartirmadi: p
qo'shib qo'ydi muallif Dawid, manba

Probably ..... Instead of if(isset($_GET['submit1'])) Use if(isset($_POST['submit1']))

0
qo'shib qo'ydi
Sizni sevaman, aniq
qo'shib qo'ydi muallif Dawid, manba

Probably ..... Instead of if(isset($_GET['submit1'])) Use if(isset($_POST['submit1']))

0
qo'shib qo'ydi
Sizni sevaman, aniq
qo'shib qo'ydi muallif Dawid, manba
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin