开发者

Get Error from the same value added on the table php

Hello every one this is simple problem. I am working on a PHP project reserve subject of student. When I click the subject from another table it display to other table dynamically,the problem is how to get the error with the same value that added on the table?

here is the code subject:

$sql = mysql_query("SELECT * FROM tblsubjecschedule ORDER BY Subject");

$i=0;
$b =1;
while($row=mysql_fetch_assoc($sql) ){


echo "<tr><td>".$row['Subject']."<input type='hidden' name='subj[$i]' value=".$row['Subject']."></td>
<td>".$row['Lec']."<br/>".$row['Lab']."<input type='hidden' name='leclab[$i]' value=".$row['Lec']."><input type='hidden' name='lab[$i]' value=".$row['Lab']."></td>

<td>".$row['Descriptive']."<input type='hidden' name='desc[$i]' value=".$row['Descriptive']."></td>
<td>".$row['Day']."<br/>".$row['Labday']."<input type='hidden' name='daylabday[$i]' value=".$row['Day']."><input type='hidden' name='labday[$i]' value=".$row['Labday']."></td>

<td>".$row['LecTime']."<br/>".$row['LabTime']."<input type='hidden' name='lectlabt[$i]' value=".$row['LecTime']."><input type='hidden' name='labtime[$i]' value=".$row['LabTime']."></td>

<td>".$row['Room']."<br/>".$row['Labroom']."<input type='hidden' name='roomlabroom[$i]' value=".$row['Room']."><input type='hidden' name='labroom[$i]' value=".$row['Labroom']."></td>

<td><input id='send' name='reserv[$i]' type='submit' value='Add' onclick='addRow('myTable')' /> </td></tr>";

$i++;


}
  if (isset($_POST['reserv'])){
 if(!empty($_POST['reserv'])){
         $a = current(array_keys($_POST['reserv']));
  $subj=$_POST['subj'][$a];
 $leclab=$_POST['leclab'][$a];
 $lab=$_POST['lab'][$a];
 $labday=$_POST['labday'][$a];
 $desc=$_POST['desc'][$a];
 $daylab=$_POST['daylabday'][$a];
 $lectlabt=$_POST['lectlabt'][$a];
 $labtime=$_POST['labtime'][$a];
 $roomLabroom=$_POST['roomlabroom'][$a];
 $labroom=$_POST['labroom'][$a];



    }
    }


?>

and here is the code that display the subject added:

<table border="1" id="myTable" style='width: 900px;'>

<thead>
<tr>
    <th>SubjectCode <th>Units <th>Time <th>Day <th>Room</th> 
</tr>
</thead>

 <?php
    if(isset($_POST['reserv'])){
         $_SESSION["S[]"]=array();
                $_SESSION["lec[]"]=array();
                $_SESSION["lab[]"]=array();
                $_SESSION["Day[]"]=array();
            $_SESSION["lday[]"]=array();
            $_SESSION["lect[]"]=array();
                $_SESSION["labt[]"]=array();
            $_SESSION["room[]"]=array();
            $_SESSION["lroom[]"]=array();
                if (isset($_SESSION["counter"])){
                    $_SESSION["counter"]=$_SESSION["counter"]+1;
                    $counter=$_SESSION["counter"];
                }else{$_SESSION["counter"]=0;
                    $counter=$_SESSION["counter"];
                }

                    $counter=$_SESSION["counter"];


                            $_SESSION["S['$counter']"]=$subj;
                         $_SESSION["lec['$counter']"]=$leclab;
                         $_SESSION["lab['$counter']"]=$lab;
                         $_SESSION["Day['$counter']"]=$daylab;
                          $_SESSION["lday['$counter']"]=$labday;
开发者_运维百科                         $_SESSION["lect['$counter']"]=$lectlabt;
                         $_SESSION["labt['$counter']"]=$labtime;
                         $_SESSION["room['$counter']"]=$roomLabroom;
                         $_SESSION["lroom['$counter']"]=$labroom;




            $c=0;
            while($c<=$counter){
                if($_SESSION["S['$c']"]==""){echo "-";}

            echo "<tr><td>".$_SESSION["S['$c']"] . "</td>
            <td>".$_SESSION["lec['$c']"] . "<br/>".$_SESSION["lab['$c']"] . "</td>
            <td>".$_SESSION["lect['$c']"] . "<br/>".$_SESSION["labt['$c']"] . "</td>
            <td>".$_SESSION["Day['$c']"] . "<br/>".$_SESSION["lday['$c']"] . "</td>
            <td>".$_SESSION["room['$c']"] . "<br/>".$_SESSION["lroom['$c']"] . "</td></tr><br>";
                 $unit=$_SESSION["lec['$c']"] + $_SESSION["lab['$c']"];
            $c=$c+1;

              $units= $units+$unit;
            }


        }


 echo"<input id='send' name='reset' type='submit' value='reset' />";
    if(isset($_POST['reset'])){
            unset($_SESSION['name']);
            unset($_SESSION['counter']);
            unset($_SESSION[$_SESSION['counter']]);

        }

 ?>

thanks in advance


You can add unique index to control your field uniqueness value, and use insert ignore which would NOT insert value if exact value exists... And you can check if value was inserted with affected rows.

That's my answer if I understood you correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜