Jadvaldagi foydalanuvchilarni tasdiqlash - katakchani belgilang

Men sahifamda ro'yxatdan o'tgan foydalanuvchilarni tasdiqlash uchun PHP skriptini yozyapman, lekin ularni tasdiqlamoqchi bo'lganimda biroz muammoga duch keldim. Mana, men imkon qadar.

Jadval:

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("activation") or die(mysql_error());
//User Approval Script
$result2 = mysql_query("SELECT * FROM userinfo WHERE status='0'") 
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Action</th> <th>Hours</th> <th>Approve</th> </tr>";
while($row = mysql_fetch_array( $result2 )) {
 // Print out the contents of each row into a table
 echo "<tr><td>"; 
 echo $row['first_name'];
 echo "</td><td>"; 
 echo $row['last_name'];
 echo "</td>"; 
 echo "<td>"; 
 echo $row['email'];
 echo "</td><td>";
 echo "<form action=\"approve.php\" method=\"post\"><input name=\"approve[]\" type=\"checkbox\">";
 echo "</td></tr>";
}
echo "</table>";
echo "<input type=\"submit\" value=\"Approve\"></form>";
?>

approve.php

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("activation") or die(mysql_error());
$ticked = $_POST['approve'];

foreach($ticked as $id) {
     mysql_query("UPDATE status SET approved = '1' WHERE `ID` = '$id'");
}
unset($id);  
?>

Men tasdiqlangan har bir foydalanuvchiga qanday qilib elektron pochta xabarlarini yuborishim mumkinligini ham bilmoqchiman...

Hammaga oldindan rahmat!

Tahrirlash:

approve.php sahifasi bo'sh va status yangilanmayapti.


php
person Jogn Smit    schedule 06.12.2013    source manba
comment
Va sizning muammoingiz nima? Iltimos, aniq bo'ling.   -  person scrowler    schedule 06.12.2013
comment
Sizning kodingiz SQL Injection uchun juda zaif. PHP-da SQL in'ektsiyasini qanday oldini olishim mumkin? va Nega PHP da mysql_* funksiyalaridan foydalanmasligim kerak?.   -  person Madara's Ghost    schedule 06.12.2013
comment
PHP mail() funksiyasidan foydalaning - Ref: php.net/manual/en/function.mail.php   -  person Krish R    schedule 06.12.2013


Javoblar (3)


Buni sinab ko'rsangiz bo'ladimi, <form> tegi yaqin katagidan tepaga ko'chirildi va $row["id"] bilan belgilash katagiga qiymati qo'shildi.

<?php
        mysql_connect("localhost", "root", "") or die(mysql_error());
        mysql_select_db("activation") or die(mysql_error());
        //User Approval Script
        $result2 = mysql_query("SELECT * FROM userinfo WHERE status='0'") 
        or die(mysql_error());
        echo "<form action=\"approve.php\" method=\"post\"><table border='1'>";
        echo "<tr> <th>Name</th> <th>Action</th> <th>Hours</th> <th>Approve</th> </tr>";
        while($row = mysql_fetch_array( $result2 )) {
         // Print out the contents of each row into a table
         echo "<tr><td>"; 
         echo $row['first_name'];
         echo "</td><td>"; 
         echo $row['last_name'];
         echo "</td>"; 
         echo "<td>"; 
         echo $row['email'];
         echo "</td><td>";
         echo "<input name=\"approve[]\" type=\"checkbox\" value='".$row["id"]."' >";
         echo "</td></tr>";
        }
        echo "</table>";
        echo "<input type=\"submit\" value=\"Approve\"></form>";
?>

approve.php da,

<?php
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("activation") or die(mysql_error());
    $ticked = $_POST['approve'];

    foreach($ticked as $id) {
         mysql_query("UPDATE status SET approved = '1' WHERE `ID` = '$id'");

         $message ='Approved message';

         mail('to email address', 'Your Subject', $message);
    }

 ?>

Eslatma: mysql_* funksiyalaridan foydalanish o‘rniga mysqli_* yoki PDO funksiyalaridan foydalaning (eslatma).

person Krish R    schedule 06.12.2013

Siz while tsiklida shaklni ochishga harakat qildingiz va tasdiqlash qutisiga value atributini o'tkazib yubordingiz.

O'zgartirish

echo "<form action=\"approve.php\" method=\"post\"><input name=\"approve[]\" type=\"checkbox\">";

Kimga

echo '<input name="approve" type="checkbox" value='.$row["id"].'>';

Keyin echo "<form action ='approve.php' method='post'>"; ni while($row = mysql_fetch_array( $result2 )) { ustiga qo'ying

person Richat CHHAYVANDY    schedule 06.12.2013

Sizda bitta katta shakl bo'lishi kerak, unda ko'p katakchalar mavjud (menimcha, sizning ikkinchi sahifangiz shunga asoslanadi), lekin katakchalar <form>s emas, <input>s. Sizning oxirgi HTMLingiz quyidagicha ko'rinishi kerak:

<form>
    <table>
    ...
    <td><input type="checkbox" name="approve[]" value="USERIDTHATYOUWANTTOAPPROVE"></td>
    ...
    <td><input type="checkbox" name="approve[]" value="OTHERUSERIDTHATYOUWANTTOAPPROVE"></td>
    ...
    </table>
</form>

Shuningdek!

person Madara's Ghost    schedule 06.12.2013